After adding <Nullable>enable</Nullable> or #nullable enable, I ran into the following problem with my Generic methods:
This does not work:
public T? GetDefault<T>()
{
return default;
}
This works with warning:
public T GetDefault<T>()
{
return default;
}
This works individually, but not together.
public T? GetDefault<T>() where T : class
{
return default;
}
public T? GetDefault<T>() where T : struct
{
return default;
}
Logically, the first method should work.
What is the correct way (in any framework) out of this situation without creating several methods and suppressing warnings?
[MaybeNull] attribute only works with .Net Core 3.0+.
Also, I asked this questions here


