Is there a way to retain the class inheritance in c# while at the same time obeying the interface inheritance rules of COM interop? Or in a different sense, how can one duplicate the functionality of AutoDual with explicit interfaces?
I've received an API library written in C# from another company that uses Microsoft.Runtime.InteropServices. I am using it to compile to a DLL which our legacy software (in powerbuilder) uses to call the API. I'm trying to use ClassInterfaceType.None
to avoid ClassInterfaceType.AutoDual
which may break the functionality in the future. I am running into the following issue:
The company who wrote the API library used good Object Oriented design. While this reduces redundancy in the c# code, it works against my purposes because of the class inheritance structure going against COM interface requirements. E.g. the Get methods for each request (there are many) call the same method which expects an inherited generic type:
Generic Method:
private T Get<T>(string Foo, string Bar) where T : UmbrellaResponse, new() { /* get the response*/ }
Two of many specific methods:
namespace SeparateFromTheObjects
{
public SpecificResponse1 GetSpecificResponse1(string token)
{
return Get<SpecificResponse1>(token, "specific_thing");
}
public SpecificResponse2 GetSpecificResponse2(string token)
{
return Get<SpecificResponse2>(token, "specific_thing");
}
}
Which currently inherits like this:
public class SpecificResponse : UmbrellaResponse
So if I create an interface with all needed properties/methods and change it to SpecificResponse : ISpecificResponse
or even : IUmbrellaResponse
, all the methods can't be used because they no longer inherit from the CLASS UmbrellaResponse.
Basically, is there a way to retain the class inheritance in c# while at the same time obeying the interface inheritance rules of COM interop? Or in a different sense, how can one duplicate the functionality of AutoDual with explicit interfaces?
If impossible, how can you write methods (such as the get method above) to accommodate multiple objects that do not inherit from the same type?
I have read the following, but do not believe it contains an answer: Why should I not use AutoDual?