UPDATE: As of C# 7.3, this should no longer be an issue. From the release notes:
When a method group contains some generic methods w
If T matches multiple constraints, you create an ambiguity that cannot be automatically resolved. For example you have one generic class with the constraint
where T : IFirst
and another with the constraint
where T : ISecond
You now want T to be a class that implements both IFirst and ISecond.
Concrete code example:
public interface IFirst
{
void F();
}
public interface ISecond
{
void S();
}
// Should the compiler pick this "overload"?
public class My where T : IFirst
{
}
// Or this one?
public class My where T : ISecond
{
}
public class Foo : IFirst, ISecond
{
public void Bar()
{
My myFoo = new My();
}
public void F() { }
public void S() { }
}