I have simplified the code but basically this code runs on a loop and the types come from reflection. The only constant here is the IWorker<T> interface.
I need to access the properties of the IWorker but I can't cast it as the argType is not accepted by the compiler, any ideas?
(I could do this with dynamic but I was hoping for an alternative to prevent future bugs due to refactoring)
Type argType = @interface.GetGenericArguments().First();
var worker = (IWorker<argType>)FormatterServices.GetUninitializedObject(MyType);
MyType derives from IWorker<T> where T is unknown at compile time.