相关疑难解决方法(0)

使用.NET/C中的委托加速Reflection API

这篇文章有评论if you need to call the method multiple times, use reflection once to find it, then assign it to a delegate, and then call the delegate..

  • 如何以及为何delegate更快地运作?谁能有一些例子吗?
  • 我可以打电话给你caching吗?如果是这样,除了使用委托的缓存方法之外还有其他方法吗?

添加

我想出了一个delegate 在这里使用的例子.

.net c# reflection delegates

7
推荐指数
1
解决办法
3392
查看次数

示例:使用.NET/C#中的委托加速Reflection API

由于被要求在这个岗位,我想出了一个使用委派用来加快在.NET/C#恢复体力的例子.

但是,运行时出现此错误(编译工作正常).可能有什么问题?

Unhandled Exception: System.ArgumentException: type is not a subclass of Multicastdelegate
  at System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, Boolean throwOnBindFailure, Boolean allowClosed) [0x00000] in <filename unknown>:0 
  at System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodInfo method, Boolean throwOnBindFailure) [0x00000] in <filename unknown>:0 
  at System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodInfo method) [0x00000] in <filename unknown>:0 
  at EX.RefTest.DelegateTest () [0x00000] in <filename unknown>:0 
  at EX.RefTest.Main () [0x00000] in <filename unknown>:0 
Run Code Online (Sandbox Code Playgroud)

添加

这是(工作)源代码,感谢Jon&ChaosPandion的帮助.

using System.Reflection;
using System;

namespace EX
{
    public class Hello
    {
        // …
Run Code Online (Sandbox Code Playgroud)

.net c# reflection delegates

5
推荐指数
1
解决办法
5458
查看次数

标签 统计

.net ×2

c# ×2

delegates ×2

reflection ×2