Is it possible to add a property to a type through DynamicProxy?

I use Castle DynamicProxy to create a proxy of a certain type at runtime, including a pair of mixins.

I am trying to figure out whether it is possible to add arbitrary properties to the proxy, for example:

class BaseType
{
  string Foo { get; set; }
}

and at runtime I create a new type that will look like this:

class BaseTypeProxy3848484etc
{
  string Foo { get; set; }
  OtherType Bar { get; set; }
}

In theory, it seems that this should be possible - maybe I just don’t see how to do this with the Castle ... Any thoughts? Thanks!

+3
source share
1 answer

The DynamicObject extension allows you to create a proxy server for your instance and add behavior to the properties you want to add.

0
source

Source: https://habr.com/ru/post/1625498/


All Articles