I have an interface like this:
public interface SomeInterface<A, B, C>
where A : SomeAClass, SomeAClass2
where B : SomeBClass
where C : SomeCClass, SomeBClass, EtcClass
{
A ObjA { get; }
B ObjB { get; }
IList<C> ObjC { get; }
}
My classes inherit this interface. My question comes from my extension methods. If I do this:
public static bool DoesThisCompile<A, B, C>(this SomeInterface<A, B, C> i)
/*
where A : SomeAClass, SomeAClass2
where B : SomeBClass
where C : SomeCClass, SomeBClass, EtcClass
*/
{
return false;
}
It doesn't work, and copy-pasting the constraints (for many extension methods) from the interface is a lot of work, very ugly, and in my opinion, unnecessary. Is there some attribute I can place somewhere or some compiler flag to automatically grab the correct constraints? I know I can create another non-generic interface, but I really do not want to do that for this project (design-wise it doesn't help and just adds lots of bloat to my classes), and it wouldn't even work because of collections.