I’m implementing an interface in order to inject custom business logic into a framework that utilizes Microsoft Unity. My core issue is that a the interface I need to implement defines the following method:
T InterfaceMethod<T>();
T has no constraints. In my code, I need to call a method from a different 3rd party library, with a method signature of
T AnotherMethod<T>() where T: class;
The type T is significant to the logic of AnotherMethod. Is there any way to call AnotherMethod<T>() within my implementation, without using reflection? I obviously need to take alternate action if T is a value type. Is there perhaps a way to autobox to work around this?
I don’t think that what you’re looking for is possible without reflection. At best, you could just call
AnotherMethod<object>()and cast the result. But this would only really work right ifAnotherMethod‘sTisn’t important for your purposes.