Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Generics Multiple Inheritance Problem

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!

like image 270
Ed Ayers Avatar asked Dec 05 '22 02:12

Ed Ayers


1 Answers

class SomeClass<T>: SomeOtherClass<T>, IAnotherInterface where T: ISomeInterface
{
...
}
like image 115
mqp Avatar answered Dec 20 '22 20:12

mqp