开发者

Check method signature before creating delegate

开发者 https://www.devze.com 2022-12-17 22:44 出处:网络
I have two delegates. I want to use reflection to load an assembly/classes and to go through each class to see if the static methods in the class match the delegates.

I have two delegates. I want to use reflection to load an assembly/classes and to go through 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 s开发者_如何学Goeem to find any method to check if it matches the delegate and i really dont want to try create and catch exceptions.

thanks


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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消