Skip to content

Commit

Permalink
Update NullabilityInfoExtensions.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Dec 20, 2024
1 parent 5984b89 commit ceef80f
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/Polyfill/Nullability/NullabilityInfoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ namespace Polyfills;
#endif
static partial class Polyfill
{
static ConcurrentDictionary<ParameterInfo, NullabilityInfo> parameterCache = [];
static ConcurrentDictionary<PropertyInfo, NullabilityInfo> propertyCache = [];
static ConcurrentDictionary<EventInfo, NullabilityInfo> eventCache = [];
static ConcurrentDictionary<FieldInfo, NullabilityInfo> fieldCache = [];
static ConcurrentDictionary<ParameterInfo, NullabilityInfo> parameters = [];
static ConcurrentDictionary<PropertyInfo, NullabilityInfo> properties = [];
static ConcurrentDictionary<EventInfo, NullabilityInfo> events = [];
static ConcurrentDictionary<FieldInfo, NullabilityInfo> fields = [];

public static NullabilityInfo GetNullabilityInfo(this MemberInfo info)
{
Expand Down Expand Up @@ -52,7 +52,7 @@ public static bool IsNullable(this MemberInfo info)
}

public static NullabilityInfo GetNullabilityInfo(this FieldInfo info) =>
fieldCache.GetOrAdd(
fields.GetOrAdd(
info,
static inner =>
{
Expand All @@ -70,7 +70,7 @@ public static bool IsNullable(this FieldInfo info)
}

public static NullabilityInfo GetNullabilityInfo(this EventInfo info) =>
eventCache.GetOrAdd(
events.GetOrAdd(
info,
static inner =>
{
Expand All @@ -88,7 +88,7 @@ public static bool IsNullable(this EventInfo info)
}

public static NullabilityInfo GetNullabilityInfo(this PropertyInfo info) =>
propertyCache.GetOrAdd(
properties.GetOrAdd(
info,
static inner =>
{
Expand All @@ -106,7 +106,7 @@ public static bool IsNullable(this PropertyInfo info)
}

public static NullabilityInfo GetNullabilityInfo(this ParameterInfo info) =>
parameterCache.GetOrAdd(
parameters.GetOrAdd(
info,
static inner =>
{
Expand All @@ -123,35 +123,35 @@ public static bool IsNullable(this ParameterInfo info)
return IsNullable(info.Name!, nullability);
}

static NullabilityState GetReadOrWriteState(NullabilityInfo nullability)
static NullabilityState GetReadOrWriteState(NullabilityInfo info)
{
if (nullability.ReadState == NullabilityState.Unknown)
if (info.ReadState == NullabilityState.Unknown)
{
return nullability.WriteState;
return info.WriteState;
}

return nullability.ReadState;
return info.ReadState;
}

static NullabilityState GetKnownState(string name, NullabilityInfo nullability)
static NullabilityState GetKnownState(string name, NullabilityInfo info)
{
var read = nullability.ReadState;
var read = info.ReadState;
if (read != NullabilityState.Unknown)
{
return read;
}

var write = nullability.WriteState;
var write = info.WriteState;
if (write != NullabilityState.Unknown)
{
return write;
}

throw new($"The nullability of '{nullability.Type.FullName}.{name}' is unknown. Assembly: {nullability.Type.Assembly.FullName}.");
throw new($"The nullability of '{info.Type.FullName}.{name}' is unknown. Assembly: {info.Type.Assembly.FullName}.");
}

static bool IsNullable(string name, NullabilityInfo nullability) =>
GetKnownState(name, nullability) == NullabilityState.Nullable;
static bool IsNullable(string name, NullabilityInfo info) =>
GetKnownState(name, info) == NullabilityState.Nullable;
}

#endif

0 comments on commit ceef80f

Please sign in to comment.