Consider the method in the interface:
public Interface IA {
T[] Get<T>() where T : IB;
}
Elsewhere, I would call this method n times for n types that are known at compile time. The following code illustrates my intent.
foreach(Type t in new Type[] { typeof(X), typeof(Y), typeof(Z) })
{
InterfaceXYZImplement[] arr = c.Resolve<IA>().Get<t>();
}
Now the loop foreachobviously makes the type become runtime, so I would have to use it MakeGenericMethod.
Is there a way to write the code so that I can execute the code for X, Yand Z, but call the method written only once?
Wrapping the code in the method will only move the problem up (which is a partial solution, but not the final one, heh).
source
share