开发者

Is it possible to add a property to a type, via a DynamicProxy?

开发者 https://www.devze.com 2023-01-09 19:05 出处:网络
I\'m using Castle DynamicProxy to create a proxy of a given type at runtime - including a couple mixins.

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

精彩评论

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