Note that there are some explanatory texts on larger screens.

plurals
  1. PODLR return type
    primarykey
    data
    text
    <p>I need some DLR help. I am implementing an IDynamicMetaObjectProvider and DynamicMetaObject but I am having some issues getting the expected return type. I am overiding BindInvokeMember in the metaobject, I can see all the args types but no return type. Anyone know how I get to it if possible? I know the return type is dynamic but what if the thing you are invoking is dependent on a return type. I don't know which action to perform in the DynamicMetaObject unless I know the return type the consumer is expecting.</p> <h2><strong>Update Two</strong></h2> <p>I cant paste my actual code here since it calls all kinds of work stuff. Some sample dynamic object code is below. </p> <pre><code>public class TestDynamicMetaObject : DynamicMetaObject { public TestDynamicMetaObject(Expression expression, object value) : base (expression, BindingRestrictions.Empty, value) { } public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args) { Delegate method = new Func&lt;int&gt;(Test); return new DynamicMetaObject( Expression.Call(method.Method), BindingRestrictions.GetInstanceRestriction(Expression,Value), Value ); } public static int Test() { return 10; } } public class TestDynamicObject : IDynamicMetaObjectProvider { DynamicMetaObject IDynamicMetaObjectProvider.GetMetaObject(Expression parameter) { return new TestDynamicMetaObject(parameter, this); } } </code></pre> <p>Here is where I am using.</p> <pre><code>static void Main(string[] args) { try { dynamic x = new TestDynamicObject(); int gg= x.Test(); Console.WriteLine(gg); } catch (Exception excep) { Console.WriteLine(excep); } Console.ReadLine(); } </code></pre> <p>Here is the code that the compiler creates.</p> <pre><code>private static void Main(string[] args) { try { object x = new TestDynamicObject(); if (&lt;Main&gt;o__SiteContainer0.&lt;&gt;p__Site1 == null) { &lt;Main&gt;o__SiteContainer0.&lt;&gt;p__Site1 = CallSite&lt;Func&lt;CallSite, object, int&gt;&gt;.Create(new CSharpConvertBinder(typeof(int), CSharpConversionKind.ImplicitConversion, false)); } if (&lt;Main&gt;o__SiteContainer0.&lt;&gt;p__Site2 == null) { &lt;Main&gt;o__SiteContainer0.&lt;&gt;p__Site2 = CallSite&lt;Func&lt;CallSite, object, object&gt;&gt;.Create(new CSharpInvokeMemberBinder(CSharpCallFlags.None, "Test", typeof(Program), null, new CSharpArgumentInfo[] { new CSharpArgumentInfo(CSharpArgumentInfoFlags.None, null) })); } Console.WriteLine(&lt;Main&gt;o__SiteContainer0.&lt;&gt;p__Site1.Target(&lt;Main&gt;o__SiteContainer0.&lt;&gt;p__Site1, &lt;Main&gt;o__SiteContainer0.&lt;&gt;p__Site2.Target(&lt;Main&gt;o__SiteContainer0.&lt;&gt;p__Site2, x))); } catch (Exception excep) { Console.WriteLine(excep); } Console.ReadLine(); } </code></pre>
    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.
 

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