[RESOLVED] Everything is Nullable???
It seems like C# wants you to explicitly state that a type is nullable even if it is a reference type. For example, I'm getting a warning on this line:
Code:
PropertyInfo property = type.GetProperty(attributeName);
That could easily return null. In fact, under many circumstances, it SHOULD. That means that the "property" variable can be null. The very next line in the code checks to see whether it is null.
The warning states "Converting null literal or possible null value to non-nullable type." However, PropertyInfo is a class, and all classes are nullable.
The class is here:
https://learn.microsoft.com/en-us/do...o?view=net-8.0
Changing the offending line to
Code:
PropertyInfo? property = type.GetProperty(attributeName);
does make the warning go away, but this should not be necessary.
Re: Everything is Nullable???
Quote:
Originally Posted by
Shaggy Hiker
It seems like C# wants you to explicitly state that a type is nullable even if it is a reference type. For example, I'm getting a warning on this line:
Code:
PropertyInfo property = type.GetProperty(attributeName);
That could easily return null. In fact, under many circumstances, it SHOULD. That means that the "property" variable can be null. The very next line in the code checks to see whether it is null.
The warning states "Converting null literal or possible null value to non-nullable type." However, PropertyInfo is a class, and all classes are nullable.
The class is here:
https://learn.microsoft.com/en-us/do...o?view=net-8.0
Changing the offending line to
Code:
PropertyInfo? property = type.GetProperty(attributeName);
does make the warning go away, but this should not be necessary.
https://learn.microsoft.com/en-us/do...ble-references gives a bit more background on nullable reference types and some of the ways you can control it.
Re: Everything is Nullable???
Interesting. Not really liking it, but I do understand the point.