tags:

views:

29

answers:

0

Let's say I have a class which inherits from DynamicObject:

public class DynamicBase : DynamicObject
{
   public override bool TryGetMember(GetMemberBinder binder, out object result)
    {
      //Yadda yadda yadda
    }

    //same for TrySetMember
}

and then I have a child class which inherits from DynamicBase:

public class ChildClass : DynamicBase
{
   public void SomeProperty { get; set; }
}

I'd like to monitor both the getter and setter of "SomeProperty" in the child class automatically. Currently, because SomeProperty exists in the child, methods are not routed to TryGet/SetMember or any other override of DynamicObject.

Ideally I would like this behavior after the user of the base class instantiates the object, like so:

var someInstance = new ChildClass();
someInstance.SomeProperty = "someValue" //Monitored somehow in DynamicBase

as opposed to having to create an instance of DynamicBase, with the child passed as a type (which is how Moq creates interceptors using DynamicProxy):

var someInstance = new DynamicBase<ChildClass>();

I'm wondering if:
1) This is even possible with C#?
2) If DynamicObject is the wrong base class; should I drop down to IDynamicMetaObjectProvider or something else?
3) If I need to take the route of DynamicBase to create a proxy around ChildClass with the combined behavior I'm looking for, using something like DynamicProxy to intercept calls?

Thanks