DynamicObject and Jint

I want to use the DynamicObject class under Jint , and I created a sample to execute it. The first statement passes correctly, but is not performed during the second statement.

Is there a way to do this, or do you know any other javascript mechanism that allows this to be done?

public void Jtest()
{
    Jint.JintEngine engine = new JintEngine();

    dynamic subject = new MyDynamicObject();

    dynamic x = subject.myProp.otherProp;

    Assert.AreEqual(subject, x);

    engine.SetParameter("myClass", subject);

    object result = engine.Run(@"return myClass.myProp.otherProp;");

    // result is null here
    Assert.AreEqual(subject, result);
}

public class MyDynamicObject : System.Dynamic.DynamicObject
{
    public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
    {
        result = this;
        return true;
    }
}
+3
source share
1 answer

I think the answer is in jint code. To find properties, it is based on reflection. I do not think that reflection processes dynamic objects. Perhaps the code needs to be updated to use the lambda expression. But in this case, it will no longer work on 2.0.

-, GetDynamicMemberNames. , , , Jint.

0

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


All Articles