Skip to content

Commit

Permalink
Use GetOrAdd
Browse files Browse the repository at this point in the history
  • Loading branch information
krajek authored and RehanSaeed committed Jun 16, 2021
1 parent 8c11cfd commit aea4add
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions Source/Serilog.Exceptions/Reflection/ReflectionInfoExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,7 @@ internal class ReflectionInfoExtractor
/// </summary>
/// <param name="valueType">The type for which properties are to be analyzed.</param>
/// <returns>The reflection info for relevant properties of <paramref name="valueType"/>.</returns>
public ReflectionInfo GetOrCreateReflectionInfo(Type valueType)
{
if (!this.reflectionInfoCache.TryGetValue(valueType, out var reflectionInfo))
{
reflectionInfo = this.GenerateReflectionInfoForType(valueType);
this.reflectionInfoCache.AddOrUpdate(
key: valueType,
addValueFactory: type => reflectionInfo,
updateValueFactory: (type, info) => reflectionInfo);
}

return reflectionInfo;
}
public ReflectionInfo GetOrCreateReflectionInfo(Type valueType) => this.reflectionInfoCache.GetOrAdd(valueType, valueFactory: this.GenerateReflectionInfoForType);

private static Func<object, object> GenerateFastGetterForProperty(Type type, PropertyInfo property)
{
Expand Down

0 comments on commit aea4add

Please sign in to comment.