How can I create a Delegate with types only known at run time ?
I would like to do the following :
Type type1 = someObject.getType();
Type type2 = someOt
You could create a generic method for that:
public Func GetFunc(T1 Object1, T2 Object2, MethodInfo Method)
{
return (Func)Delegate.CreateDelegate(typeof(Func<,>).MakeGenericType(typeof(T1), typeof(T2)), Method);
}
And I bet you can do something using the same philosophy with the Method to avoid all this reflection stuff.
Obs: that would work only if T1 and T2 are typed variables. If they are as object you'll get a Func. But....if the objects you will give to the method are as object as well, that would be no problem at all.
And maybe you can even use Func always, depending on your scenario.