Consider the general method:
class SomeClass
{
public static void SomeMethod<T>(Func<T>);
}
I would like to name this method using reflection. Here's how I can do it:
_SomeMethod = typeof(SomeClass).GetMethod("SomeMethod",
BindingFlags.Public | BindingFlags.Static);
Type type = typeof(SomeType); //Actually SomeType is extracted using reflection and it not fixed
MethodInfo toBeCalled = _SomeMethod.MakeGenericMethod(type);
object obj = Activator.CreateInstance(type);
toBeCalled.Invoke(null, () => obj);
But this gives a compilation error:
Error CS1660: Cannot convert `lambda expression' to non-delegate type `object' (CS1660)
Which is absolutely acceptable, but what works?
Please keep in mind that a closure created using lambda is what I need, so don't rule it out.
[UPDATE]
, ; , , , SomeMethod SomeType. functor, . - obj , , ?