3

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; }
}

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

Bobby
  • 1,666
  • 3
  • 16
  • 27
  • You can use a mixin or have the proxy implement a initerface that exposes this property – Krzysztof Kozmic Aug 03 '10 at 03:23
  • that's pretty much what I've already done, but not what I need to do - the new property names need to be determined when the proxy is created... at runtime - think of it like this, when compiled, say I have Prop1, Prop2, Pro3 etc... thenI need to add Prop1Metadata, Prop2Metadata, Prop3Metadata, etc... make sense? (thx for the quick reply) – Bobby Aug 03 '10 at 03:29
  • 1
    Yes it does make sense. No it's not possible at this point, at least not out of the box. You could extend DP to add this but currently it won't be very easy as DP is very focused on doing what it does - proxying, which excludes scenario like this one. – Krzysztof Kozmic Aug 03 '10 at 03:58
  • ok, understood. Thanks for the clarification. Other than DynamicProxy, is there some other way of doing this? If not I suppose I'll need to think of a different approach.. – Bobby Aug 03 '10 at 19:11
  • Not that I know of. It wouldn't be _very_ hard to do with DP though – Krzysztof Kozmic Aug 05 '10 at 06:50

1 Answers1

0

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

Ivo
  • 8,172
  • 5
  • 27
  • 42