Skip to content

Reflect nullability with new C# 8 feature #9662

Closed

Description

@RicoSuter

How can we reflect over the nullability of props, params etc e.g. for string vs string? with the new C# 8 nullability output? Is there a new api for that?

See https://blog.rsuter.com/the-output-of-nullable-reference-types-and-how-to-reflect-it/


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Activity

  1. added this to the milestone on Jan 14, 2019
  2. BillWagner commented on Jan 14, 2019

    @BillWagner
    Member

    Thanks for bringing this to our attention @RSuter It's a very good point.

    Preview 1 is a bit early for this content, as some details are still being discussed and subject to change. I've tagged it for the .NET Core 3 release, and added a milestone to make sure we cover this in one of the later previews.

  3. RicoSuter commented on Jan 15, 2019

    @RicoSuter
    Author

    Is there already some discussions, description, info about that? Can you provide some links e.g. to GitHub issues?

  4. modified the milestones: , March 2019 on Feb 25, 2019
  5. self-assigned this
    on Feb 25, 2019
  6. jcouv commented on Mar 14, 2019

    @jcouv
    Contributor

    It should be possible to figure this out via reflection, but not trivial.

    The Nullable attribute is generated so that it stores the relevant flags, so that the flags are accessible via reflection.
    Once you have the flags, you’d need to decode them (which requires traversing the tree of nested types). The decoding is similar to that of dynamic.
    Here’s our doc on encoding:
    https://github.com/dotnet/roslyn/blob/master/docs/features/nullable-reference-types.md#annotations

    I can also dig up the section of our tests that cover this, if that helps.

    I'm curious to understand the scenarios where this is useful to get this information at runtime via reflection. Can you share some more details?

  7. BillWagner commented on Mar 14, 2019

    @BillWagner
    Member

    @jcouv From the blog post @RSuter references above:

    I’m writing libraries to generate JSON Schema (NJsonSchema) and OpenAPI/Swagger specs (NSwag). These libraries rely heavily on reflection. I looked into the Nullable Reference Types feature because I’d really like to use it in these generators…

  8. 16 remaining items

  9. RicoSuter commented on Sep 30, 2019

    @RicoSuter
    Author
  10. added
    won't fix
    on Jan 25, 2021
  11. dotnet-bot commented on Jan 25, 2021

    @dotnet-bot
    Contributor

    This issue has been closed as part of the issue backlog grooming process outlined in #22351.

    That automated process may have closed some issues that should be addressed. If you think this is one of them, reopen it with a comment explaining why. Tag the @dotnet/docs team for visibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

blockeddotnet-csharp/svcwon't fix

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions