Not understanding why these to Map methods have the same parameter types, since they don't appear too. Is this a covariance thing or just a generic signature thing?
I would like to understand it in general to avoid writing code that will have this problem. (And explain the catch-22 of how it is both the same and not-the-same)
class A { }
class B
{
void Map<T>(T obj) where T : A { }
void Map<T>(T obj) where T : B { } // SAME -- "Map" already defined, can't compile
void Test(A a, B b)
{
Map(a);
Map(b); // NOT SAME -- if the B-mapper is removed then this won't compile
}
}
This change will "fix" it: void Map<T>(in T obj) ??
This seems even more "Not the Same":
Ta Map<Tb, Ta>(Tb obj) where Ta: A, new() where Tb : B, new() { return new Ta(); }
Tb Map<Ta, Tb>(Ta obj) where Ta: A, new() where Tb : B, new() { return new Tb(); } // ERROR
E.g., want to Map<Tsrc, Tdest> from Tsrc to Tdest, by convention, but can't. Need swap generic order:
Ta Map<Ta, Tb>(Tb obj) where Ta: A, new() where Tb : B, new() { return new Ta(); }
Tb Map<Ta, Tb>(Ta obj) where Ta: A, new() where Tb : B, new() { return new Tb(); } // OK NOW
Note: in these last two cases the parameter types are not changed, even though one is legal and the other isn't.
The in invariance modifier would also fix this, which I believe is a clue to understanding what is going on.