C # Generics Multiple Inheritance Problem

Can someone help me with this syntax issue with C #? I do not know how to do that.

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

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

The problem seems to be that the where keyword twists everything so that the compiler thinks that ISomeInterface and IAnotherInterface should be inherited by T.

This problem is very annoying, and I think the solution is a kind of bracket, but I tried and could not find the one that works. In addition, switching the order of two elements inherited from SomeClass does not work, because the inherited class should always appear in front of any interfaces. I could not find any solutions on the C # MSDN common file pages, and I cannot believe that I am the first person to have this problem.

Thanks, any help is much appreciated!

+3
source share
1 answer
class SomeClass<T>: SomeOtherClass<T>, IAnotherInterface where T: ISomeInterface
{
...
}
+15
source

Source: https://habr.com/ru/post/1747410/


All Articles