Call IDynamicMetaObjectProvider members without reference to Microsoft.CSharp.dll

I have a dynamic value (implementation of IDynamicMetaObjectProvider), which I would call methods and properties.

Examples that I have found so far for calling members in dynamic value types from Microsoft.CSharp.dll, for example.

IDynamicMetaObjectProvider x = GetDynamicValue(); CallSite<Func<CallSite, object, object, object>> site = CallSite<Func<CallSite, object, object, object>>.Create( Binder.SetMember( Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags.None, "Foo", null, new[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) } ) ); site.Target(site, x, 42); 

I want to be able to call IDynamicMetaObjectProvider elements without using the Microsoft.CSharp.dll file. Please note that I'm not talking about using the C # dynamic keyword in everything that is related to C #, but IDynamicMetaObjectProvider is directly used.

Also note that using Reflection will not work. Reflection bypasses dynamic call binding and simply performs Reflection on the base type. I need a method that works with any implementation of IDynamicMetaObjectProvider.

+4
source share
1 answer

You will need to implement your own CallSiteBinder , since there is no agnostic for CallSiteBinders. Basically the idea is that Binder handles the subtle differences between the information provided from your call languages ​​in order to select the correct member to bind to any object, regardless of language.

Since this is not like binding a CSharp Binder to an IronPython object, the flexibility of using different binders, according to the language of the library users, depends on what kind of flexibility you provide through your library. Given the above example, if you do not allow library users to change any parameters of the binder, then it will be good for you using CSharp Binder, if you suggested more, it might be useful to offer to abandon the binder through dependency injection or an overloaded method.

However, I think that CSharpBinder should be fine if you want to pass only some parameters of the binder, because the csharp binder gives you pretty good flexibility, the binder is wise (with one exception, that is not going to change the case insensitive bindings), and this is really the best the choice for binders in the shared library, as this is the only language binder that includes the standard in the .net 4.0 installation and the Mono 2.8 installation.

+3
source

All Articles