Skip to content

Latest commit

 

History

History
40 lines (32 loc) · 885 Bytes

QW0009.md

File metadata and controls

40 lines (32 loc) · 885 Bytes

QW0009: Define properties as not-nullable for enums with a defined none value

The purpose of Nullable<T> is to provide an additional null (or empty) value on top of its underlying value.

Enums that define a None or Empty value (as their default) have a well defined empty/null state. Creating models with those types as nullables is inconvenient as the check .HasValue still does not tell if the value is not empty.

Non-compliant

SomeClass
{
    public MyENum? Value { get; }
}

SomeRecord(MyENum? Value);

enum MyENum
{
    None = 0,
}

Compliant

SomeClass
{
    public MyENum Value { get; }
}

SomeRecord(MyENum Value);

enum MyENum
{
    None = 0,
}