I have a set of classes that use generics and generic constraints fairly heavily and I have hit an issue, while not a show stopper, makes the code quite cumbersome. I get an issue where the compiler is telling me it cannot convert a one parameter to another type when the two are related
I have created a simplified repro below
class Foo
{
}
class Quux<TFoo> : Bar where TFoo : Foo
{
public Quux(Spong<Bar> spong)
{
}
}
class Baz : Quux<Foo>
{
public Baz(Spong<Baz> bf) : base(bf)
{
}
}
class Spong<TBar> where TBar : Bar
{
}
class Bar
{
}
It is the constructor of Baz that has the issue where forwarding to the base class has the following compiler error
CS1503 Argument 1: cannot convert from 'TestGenericWeirdness.Spong<TestGenericWeirdness.Baz>' to 'TestGenericWeirdness.Spong<TestGenericWeirdness.Bar>'
When these two types are clearly related via Quux
Only by changing the code to
public Baz(Spong<Bar> bf) : base(bf)
{
}
Does the error go away. Now you may say "Its really not that big a deal" but the real code is integrating with Aspnet.Identity and has 8 not 1 generic arguments that would have to be fully specified
Anyone know what the issue is and / or a workaround?