Skip to content
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

Support checking for required members in minimal APIs #45084

Merged

Conversation

captainsafia
Copy link
Member

Part of #40099.

  • Using required on a reference type in an oblivious nullability context makes it non-optional.
  • Using required on a nullable type means it is non-optional. required necessitates the initialization of values which we already do in RDF, nullability allows them to be initialized to null.

NullabilityState.Nullable => true,
// In an oblivious context, the required modifier makes
// members non-optional
NullabilityState.Unknown => !GetCustomAttributes(true).OfType<RequiredMemberAttribute>().Any(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How often does this get called?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is NullabilityState.Unknown the same as having Disabled for nullable references?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is NullabilityState.Unknown the same as having Disabled for nullable references?

Yep, this represents an oblivious nullability context AKA <Nullable>disable</Nullable>.

How often does this get called?

Under an oblivious nullability context, it'll be called for every property in the AsParameters call. We can probably cache this value on PropertyAsParameterInfo as needed.

@captainsafia captainsafia marked this pull request as draft November 15, 2022 19:37
@captainsafia captainsafia marked this pull request as ready for review November 29, 2022 06:09
@captainsafia captainsafia requested a review from a team December 14, 2022 18:29
src/Shared/PropertyAsParameterInfo.cs Outdated Show resolved Hide resolved
@captainsafia captainsafia enabled auto-merge (squash) January 3, 2023 17:53
@captainsafia captainsafia merged commit 1099d06 into dotnet:main Jan 3, 2023
@ghost ghost added this to the 8.0-preview1 milestone Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants