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 5710bac commit 3b6c6b5
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/Polyfill/Nullability/NullabilityInfoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,13 @@ public static bool IsNullable(this PropertyInfo info)
}

public static NullabilityInfo GetNullabilityInfo(this ParameterInfo info) =>
parameterCache.GetOrAdd(info, static inner =>
{
var context = new NullabilityInfoContext();
return context.Create(inner);
});
parameterCache.GetOrAdd(
info,
static inner =>
{
var context = new NullabilityInfoContext();
return context.Create(inner);
});

public static NullabilityState GetNullability(this ParameterInfo info) =>
GetReadOrWriteState(info.GetNullabilityInfo());
Expand All @@ -129,16 +131,16 @@ static NullabilityState GetReadOrWriteState(NullabilityInfo nullability)

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

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

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

0 comments on commit 3b6c6b5

Please sign in to comment.