使用 Reflection.Emit 发出从另一种类型派生的类型和接口
我有一个类 A,它实现接口 I:
class A: I
{
// implementation of I
}
还有另一个接口 J,它扩展了 I:
interface J : I
{
// J methods and properties.
}
我想发出一个动态类 B,它看起来像这样:
class B : A, J
{
// All the constructors of A
// All the methods of J, which are not implemented by A. Their implementation would just throw NotImplementedException()
}
我对 Reflection.Emit 有足够的了解,可以从头开始,但是,唉,我并不是真的愿意。有谁知道可以做到这一点的图书馆吗?
谢谢。
PS
我知道 Castle 项目,但从未真正使用过它,不知道他们是否为我提供了现成的解决方案。
I have a class A, which implements interface I:
class A: I
{
// implementation of I
}
There is another interface J, which extends I:
interface J : I
{
// J methods and properties.
}
I would like to emit a dynamic class B, which would look like so:
class B : A, J
{
// All the constructors of A
// All the methods of J, which are not implemented by A. Their implementation would just throw NotImplementedException()
}
I have enough knowledge in Reflection.Emit to do it from scratch, but, alas, I do not really wish to. Does anyone know a library, which can do that?
Thanks.
P.S.
I am aware of the Castle project, but never really used it and do not know whether they have a ready solution for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您通过 DefineType 创建类型定义时,会覆盖基类和实现的接口:
http://msdn.microsoft.com/en-us/library/f53tx4x8。 ASPX
When you create type definition by DefineType there is override with base class and implemented interfaces:
http://msdn.microsoft.com/en-us/library/f53tx4x8.aspx
Castle DynamicProxy 可以用来做到这一点 。
Castle DynamicProxy can be used to do it.