我怎样才能创建的MethodInfo一个Action委托? [英] How can I create an Action delegate from MethodInfo?
本文介绍了我怎样才能创建的MethodInfo一个Action委托?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获得一个动作代表从MethodInfo的对象。这可能吗?
I want to get an action delegate from a MethodInfo object. Is this possible?
感谢你。
推荐答案
// Static method
Action action = (Action) Delegate.CreateDelegate(typeof(Action), method);
// Instance method (on "target")
Action action = (Action) Delegate.CreateDelegate(typeof(Action), target, method);
对于动作< T>
等,只是到处指定适当的委托类型
For an Action<T>
etc, just specify the appropriate delegate type everywhere.
这篇关于我怎样才能创建的MethodInfo一个Action委托?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文