C# Generics Multiple Inheritance Problem

Posted by Ciemnl on Stack Overflow See other posts from Stack Overflow or by Ciemnl
Published on 2010-05-27T17:28:31Z Indexed on 2010/05/27 17:31 UTC
Read the original article Hit count: 110

Filed under:
|
|

Can any one help me with this syntax issue with C#? I have no idea how to do it.

class SomeClass<T> : SomeOtherClass<T> where T : ISomeInterface , IAnotherInterface
{
...
}

I want SomeClass to inherit from SomeOtherClass and IAnotherInterface and for T to inherit ISomeInterface only

It seems the problem is that the where keyword screws everything up so that the compiler thinks both ISomeInterface and IAnotherInterface should both be inherited by T.

This problem is very annoying and I think the solution is some kind of parenthesis but I have tried and failed finding one that works. Also, switching around the order of the two items inherited from SomeClass does not work because the class inherited always has to come before any interfaces. I couldn't find any solutions on the MSDN C# generics pages and I can't beleive I'm the first person to have this problem.

Thanks, any help is much appreciated!

© Stack Overflow or respective owner

Related posts about c#

Related posts about generics