This is a syntax question. I have a generic class that inherits from a generic base class and applies a constraint to one of the type parameters. I also want the derived class to implement the interface. For my life, I cannot understand the correct syntax.
This is what I have:
DerivedFoo<T1,T2> : ParentFoo<T1, T2> where T2 : IBar { ... }
The first thing that came to mind was the following:
DerivedFoo<T1,T2> : ParentFoo<T1, T2> where T2 : IBar, IFoo { ... }
But this is not true, because it leads to the fact that T2 needs to implement both IBar and IFoo, and not DerivedFoo to implement IFoo.
I tried a bit of googling, using colons, semicolons, etc., but I ended up short. I am sure the answer is dizzyingly simple.
generics inheritance c # interface constraints
Dan Rigby Jan 05 '10 at 16:28 2010-01-05 16:28
source share