开发者

Is it possible to add a property to a type, via a 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开发者_Python百科 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; }
}

In theory, it seems like this should be possible-- maybe I'm just not seeing how to do it with Castle... Any thoughts? Thanks!


Extending DynamicObject you can create a proxy of your instance and add behaviour to the properties you want to add.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜