A simple class with a copy constructor, which calls another constructor:
public class Foo<TEnum> where TEnum : Enum
{
public Foo(TEnum myEnum)
{
MyEnum = myEnum;
}
public Foo(Foo<TEnum> foo) : this(foo.MyEnum) { }
public TEnum MyEnum { get; }
}
That would show warning:
warning CA1062: In externally visible method 'Foo{TEnum}.Foo(Foo{TEnum} foo)', validate parameter 'foo' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'.
I ordinarily would do this:
public Foo(Foo<TEnum> foo)
: this(foo?.MyEnum ?? throw new ArgumentNullException(nameof(foo))) { }
But that doesn't compile:
'TEnum' cannot be made nullable.
Am I missing something obvious or is this a limitation of some sort?
(I prefer not to suppress that warning as it's important; I'd like to do the validation somehow.)