You can only have multiple interface inheritance in C#. The best you can do with these third party classes is to encapsulate an instance of each in MyClass
and re-create each function call and pass it to the appropriate instance.
public class MyClass
{
ClassA a = new ClassA();
ClassB b = new ClassB();
void AMethod()
{
a.AMethod();
}
int BMethod(int value)
{
return b.BMethod(value);
}
}
If you need to be able to use this class in locations where a ClassA
, say, is required, then you can add conversion operators to convert it back to ClassA
or ClassB
. Whether it's more appropriate at that point to return new instances of these or expose your internal ones is one you would need to carefully consider.
Obviously, if ClassA
or ClassB
do implement any interfaces, I'd recommend you implement those on your new class also.
But, at the end of the day, C# doesn't have multiple implementation inheritance. If you need such (which is a rarity), then C# isn't an appropriate language. Nor is any other CLR language, since this is a CLR limitation, not specifically a C# one.