Skip to content

Correct NullabilityInfo for indexer parameters in certain circumstances #102686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,16 @@ public NullabilityInfo Create(ParameterInfo parameterInfo)
NullableAttributeStateParser parser = parameterInfo.Member is MethodBase method && IsPrivateOrInternalMethodAndAnnotationDisabled(method)
? NullableAttributeStateParser.Unknown
: CreateParser(attributes);
NullabilityInfo nullability = GetNullabilityInfo(parameterInfo.Member, parameterInfo.ParameterType, parser);

MemberInfo actualMember = parameterInfo.Member;
if (actualMember is PropertyInfo propertyInfo)
{
// NullabilityContextAttribute is annotated on the getter/setter method rather than the property itself.
// Getter & setter methods should have same nullability, if the IL is not manually edited. In such cases, there're no documented ways to determine whether the param is from getter/setter.
actualMember = (MemberInfo?)propertyInfo.GetMethod ?? (MemberInfo?)propertyInfo.SetMethod ?? propertyInfo;
}

NullabilityInfo nullability = GetNullabilityInfo(actualMember, parameterInfo.ParameterType, parser);

if (nullability.ReadState != NullabilityState.Unknown)
{
Expand Down
Loading