是否有可能扩展 System.Delegate?
在 C# 中不可能从 System.Delegate 或 System.MulticastDelegate 继承。 只要您声明标准的“运行时管理”方法,就完全可以在 MSIL 中执行此操作。 但是,每次我向该类型添加“cil 管理”方法时,我都会收到:
System.TypeLoadException: IllegalDefinition for Runtime Implemented delegate method.
Is it at all possible toextend Delegate/MulticastDelegate ?
It is not possible to inherit from System.Delegate or System.MulticastDelegate in C#. It is perfectly possible to do it in MSIL as long as you declare standard 'runtime managed' methods. However, every time I am adding a 'cil managed' method to the type, I am getting:
System.TypeLoadException: Illegal definition for runtime implemented delegate method.
Is it at all possible to extend Delegate/MulticastDelegate?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不是使用您自己的 C# 自定义代码。 来自 C# 3.0 规范第 10.1.4 节:
但是,每次创建委托类型时,都会自动从
MulticastDelegate
派生。来自 ECMA-335,第 8.9.3 节:
这听起来像是禁止构造函数。 我个人会在普通类型中使用静态方法。
Not with your own custom code, in C#. From section 10.1.4 of the C# 3.0 spec:
However, every time you create a delegate type, that automatically derives from
MulticastDelegate
.From ECMA-335, section 8.9.3:
That sounds like it's prohibiting constructors. I'd use a static method in a normal type instead, personally.
您可能有兴趣查看以下来自 Rick Strahl 的帖子,其中他比较了动态委托创建的不同方法。
You may be interested in looking at the following post from Rick Strahl where he compares different methods of dynamic delegate creation.