C#8 nullable checks

Viewed 134

I have a class with a nullable type, like this:

#nullable enable
class Foo {
    public SomeType? Name { get; }
}
#nullable restore

After checking for null, I put the instance in a list and do some other stuff with it. For a statical analyzer it gets really difficult to know, that Name is not null. Currently, the compiler complains all the time, which is annoying, and I don't really want to use the ! operator, to force him to be quiet. Somehow I want to mark the instance as "null-checked".

One option is to create a wrapper of Foo having public SomeType Name { get; }. This looks like a lot of work though.

Are there other options? Are there any future plans which tackle those situations?

0 Answers
Related