开发者

Check method signature before creating delegate

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜