Check compatibility of a method with a given Delegate?

In C# code, how do I check if a given method can be represented by a particular delegate type?

I first tried something, based on my Type knowledge, along the lines of:

// The delegate to test against.
void TargetDelegate(string msg);

// and...
var methodInfo = Type.GetMethod(..);  // obtain the MethodInfo instance. 
// try to test it 
typeof(TargetDelegate).IsAssignableFrom(methodInfo.GetType());

but that deals with only Types and not methods - it will always be false.

My inclination is to believe the answer lies in the Delegate Type, but I'm just wandering around the FCL at this point. Any help would be appreciated.

7
задан Nathan Kleyn 13 April 2013 в 20:58
поделиться