Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing DynamicObject (IDynamicMetaObjectProvider) as a component of a static type leads to infinite loop
    primarykey
    data
    text
    <p>I'm trying to create a dynamic object that can be used as a component of a static object. Here is a contrived example of what I'm trying to accomplish.</p> <p>Here is the dynamic component:</p> <pre><code>public class DynamicComponent : DynamicObject { public override bool TryInvokeMember( InvokeMemberBinder binder, object[] args, out object result) { result = "hello"; return true; } } </code></pre> <p>And here is a class where inheriting from <code>DynamicObject</code> isn't an option...assume that there is some third party class that I'm forced to inherit from.</p> <pre><code>public class AStaticComponent : VendorLibraryClass, IDynamicMetaObjectProvider { IDynamicMetaObjectProvider component = new DynamicComponent(); public DynamicMetaObject GetMetaObject(Expression parameter) { var result = component.GetMetaObject(parameter); return result; } } </code></pre> <p>The direct usage of <code>DynamicComponent</code> works:</p> <pre><code>dynamic dynamicComponent = new DynamicComponent(); Assert.AreEqual(dynamicComponent.AMethod(), "hello"); </code></pre> <p>However, forwarding the <code>GetMetaObject</code> through <code>AStaticComponent</code> causes some form of an infinite loop.</p> <pre><code>dynamic dynamicComponent = new AStaticComponent(); Assert.AreEqual(dynamicComponent.AMethod(), "hello"); //causes an infinite loop </code></pre> <p>Anyone know why this occurs? </p> <p>And if it's some baked in behavior of <code>DynamicObject</code> that I cannot change, could someone provide some help on how to create a <code>IDynamicMetaObjectProvider</code> from scratch to accomplish a component based dynamic object (just something to get things started)?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload