Jon*_*eet 63
// Static method
Action action = (Action) Delegate.CreateDelegate(typeof(Action), method);
// Instance method (on "target")
Action action = (Action) Delegate.CreateDelegate(typeof(Action), target, method);
Run Code Online (Sandbox Code Playgroud)
对于Action<T>等,只需在任何地方指定适当的委托类型.
在.NET Core中,Delegate.CreateDelegate不存在,但是MethodInfo.CreateDelegate:
// Static method
Action action = (Action) method.CreateDelegate(typeof(Action));
// Instance method (on "target")
Action action = (Action) method.CreateDelegate(typeof(Action), target);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11449 次 |
| 最近记录: |