views:

39

answers:

1

Hi,

I want to get an action delegate from a MethodInfo object. Is this possible?

Thank you.

+1  A: 

Use Delegate.CreateDelegate:

// Static method
Action action = (Action) Delegate.CreateDelegate(typeof(Action), method);

// Instance method (on "target")
Action action = (Action) Delegate.CreateDelegate(typeof(Action), target, method);

For an Action<T> etc, just specify the appropriate delegate type everywhere.

Jon Skeet