In C# 8 with nullable enabled, is there a way to identify a nullable reference type for generic type?
For nullable value type, ther
You can't use nullable in the constraint, but you can use it in the method signature. This effectively constraints it to be a nullable type. Example:
static Result> Create(Nullable value) where T : struct
{
//Do something
}
Note that you can use this side by side with your existing method, as an overload, which allows you to execute a different logic path if it's nullable versus if it is not.
static Result> Create(Nullable value) where T : struct
{
Log("It's nullable!");
Foo(value);
}
public static Result Create(T value)
{
Log("It's not nullable!");
Foo(value);
}