Skip to content
Discussion options

You must be logged in to vote

Here's the issue: you're holding it wrong (sorry). GetTypeInfo is something you call on an expression, not on a type syntax. What you wanted to do was call GetDeclaredSymbol on the local declaration; that will give the symbol that corresponds to the local, and you can then check the annotation (or Type.Annotation, either works) for the declared nullability. As an example:

#:package Microsoft.CodeAnalysis.CSharp@5.0.0
#:package Basic.Reference.Assemblies.Net100@1.8.4

using Basic.Reference.Assemblies;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;

const string Source = """
                      string? nullable = "test";

Replies: 2 comments 2 replies

This comment has been hidden.

@333fred

This comment has been hidden.

Comment options

You must be logged in to vote
1 reply
@MihaMarkic
Comment options

Answer selected by MihaMarkic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants