Monitoring calls to non-dynamic methods when working with child classes that inherit from DynamicObject

Let's say I have a class that 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 that inherits from DynamicBase:

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

I would like to automatically track both the getter and setter from "SomeProperty" in the child class. Currently, since SomeProperty exists in the child, methods are not redirected to TryGet / SetMember or any other DynamicObject override.

Ideally, I would like this behavior after the user of the base class creates an instance of the object, for example:

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

as opposed to having to instantiate a DynamicBase when the child is passed as a type (how does Moq create hooks using DynamicProxy):

var someInstance = new DynamicBase<ChildClass>();

, :

  • #?
  • DynamicObject ; IDynamicMetaObjectProvider - ?
  • DynamicBase, - ChildClass , , - DynamicProxy ?
+3
1

dynamic, 4.0. IDynamicMetaObjectProvider , .NET/. , , , , .

+1

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


All Articles