Can I somehow have overloaded methods which differ only by generic type constraints?
This does not compile:
void Foo(T bar) wh
struct _Val_Trait where T:struct { }
struct _Ref_Trait where T:class { }
static void Foo(T bar, _Ref_Trait _ = default(_Ref_Trait)) where T:class
{
Console.WriteLine("ref");
}
static void Foo(T bar, _Val_Trait _ = default(_Val_Trait)) where T:struct
{
Console.WriteLine("val");
}
static void Main()
{
Foo(1); // -->"val"
Foo(DateTime.Now); // -->"val"
Foo(""); // -->"ref"
//but:
//Foo(null); - error: type cannot be inferred
}