问题描述
我用城堡DynamicProxy在运行时创建一个特定类型的代理 - 包括一对夫妇混入
I'm using Castle DynamicProxy to create a proxy of a given type at runtime - including a couple mixins.
我试图找出是否有可能也为代理添加任意属性,例如:
I'm trying to figure out if it's possible to also add arbitrary properties to the proxy, e.g.:
class BaseType
{
string Foo { get; set; }
}
和在运行时,我创建了一个新的类型,应该是这样的
and at runtime, I create a new type, that would look like this:
class BaseTypeProxy3848484etc
{
string Foo { get; set; }
OtherType Bar { get; set; }
}
在理论上,它看起来像这样的应的被也许possible--我只是没有看到如何与城堡做...有什么想法?谢谢!
In theory, it seems like this should be possible-- maybe I'm just not seeing how to do it with Castle... Any thoughts? Thanks!
推荐答案
扩展DynamicObject您可以创建实例的代理,并添加行为,您要添加的属性。
Extending DynamicObject you can create a proxy of your instance and add behaviour to the properties you want to add.
这篇关于是否有可能将属性添加到一个类型,通过DynamicProxy?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!