I'm writing a source generator that processes my model classes and adds some custom serialisation code for them. The model classes can have all sorts of property types. I'm currently interested in the nullable enum properties. I cannot detect them. I see their name and the type as something like "MyEnum?" but I need to know if that's an enum.
For non-nullable enum types, the check is:
isEnum = classProperty.Type is INamedTypeSymbol namedType2 &&
namedType2.EnumUnderlyingType != null;
Nullables can be detected so:
isNullable = classProperty.Type is INamedTypeSymbol namedType &&
namedType.NullableAnnotation == NullableAnnotation.Annotated;
But I cannot find any combination of these. Is that possible, and how?
Updates:
The same applies to property types like int? actually. And I'd expect this to be a Nullable<int> or something. In fact I can see that the type is generic (IsGenericType == true) and its first type argument (TypeArguments[0]) is int (in the case of int?). I just can't unhide that Nullable<> part anywhere so I can never be sure if it's really the nullable situation.