tags:

views:

57

answers:

1

Hi

I have two delegates. I want to use reflection to load a assembly/classes and the go threw each class to see if the static methods in the class match the delegates.

I got everything up to getting all the methodinfos but i can seem to find any method to check if it matches the delegate and i really dont want to try create and catch exceptions.

thanks

A: 

You could use the CreateDelegate method:

// The delegate type you want to match against
var delegateType = typeof(Func<int>);
// The method info
MethodInfo someMethodInfo = ...
var del = Delegate.CreateDelegate(delegateType, someMethodInfo, false);
if (del != null) {
    // you've got a match
}
Darin Dimitrov
Cool beans so the createDelegate will just return null. thanks its a no brainer now
Pintac
Nope it tells me to go play with myself if the method signature is different
Pintac
Wasn't checking if a delegate matches a given MethodInfo without catching exceptions what you were looking for?
Darin Dimitrov