DLR Return Type

I need help DLR. I implement IDynamicMetaObjectProvider and DynamicMetaObject, but I am having some problems getting the expected return type. I surpass BindInvokeMember in a meta object, I see all args types, but it does not return a type. Does anyone know how I will get to him, if possible? I know that the return type is dynamic, but what if the thing you call depends on the return type. I do not know what action needs to be performed in DynamicMetaObject if I do not know the type of return that the consumer expects.

Update two

I can’t insert my actual code here, as it calls all kinds of work. The following is an example of dynamic object 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<int>(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); } } 

Here I use.

 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(); } 

Here is the code that the compiler creates.

 private static void Main(string[] args) { try { object x = new TestDynamicObject(); if (<Main>o__SiteContainer0.<>p__Site1 == null) { <Main>o__SiteContainer0.<>p__Site1 = CallSite<Func<CallSite, object, int>>.Create(new CSharpConvertBinder(typeof(int), CSharpConversionKind.ImplicitConversion, false)); } if (<Main>o__SiteContainer0.<>p__Site2 == null) { <Main>o__SiteContainer0.<>p__Site2 = CallSite<Func<CallSite, object, object>>.Create(new CSharpInvokeMemberBinder(CSharpCallFlags.None, "Test", typeof(Program), null, new CSharpArgumentInfo[] { new CSharpArgumentInfo(CSharpArgumentInfoFlags.None, null) })); } Console.WriteLine(<Main>o__SiteContainer0.<>p__Site1.Target(<Main>o__SiteContainer0.<>p__Site1, <Main>o__SiteContainer0.<>p__Site2.Target(<Main>o__SiteContainer0.<>p__Site2, x))); } catch (Exception excep) { Console.WriteLine(excep); } Console.ReadLine(); } 
+6
c # dynamic-binding dynamic-language-runtime
Sep 01 '09 at 0:55
source share
2 answers

For standard binaries that return something, the return type is almost always an object (get, set, operations, etc.). Otherwise, it is not valid for standard bindings (e.g. DeleteMember).

You can also get the expected return type at runtime from the ReturnType property on the incoming binder.

+5
Sep 01 '09 at 1:54
source share

It seems that the return type is at least the beta that I used, I don't know ...

I tried to make an ap / invoke example using DLR, but it doesn't seem to be possible unless you pass the expected return type as the parameter I ended up: \ It seems to me that this is a limitation. I hope it will be considered in the future.

0
Dec 11 '09 at 9:27
source share



All Articles