How do you implement C#4's IDynamicObject interface?

后端 未结 5 1022
忘掉有多难
忘掉有多难 2021-01-01 00:03

To implement \"method-missing\"-semantics and such in C# 4.0, you have to implement IDynamicObject:

public interface IDynamicObject
{
  MetaObject GetMetaObj         


        
5条回答
  •  爱一瞬间的悲伤
    2021-01-01 00:51

    Here is what I have figured out so far:

    The Dynamic Language Runtime is currently maintained as part of the IronPython project. So that is the best place to go for information.

    The easiest way to implement a class supporting IDynamicObject seems to be to derive from Microsoft.Scripting.Actions.Dynamic and override the relevant methods, for instance the Call-method to implement function call semantics. It looks like Microsoft.Scripting.Actions.Dynamic hasn't been included in the CTP, but the one from IronPython 2.0 looks like it will work.

    I am still unclear on the exact meaning of the "parameter"-parameter, but it seems to provide context for the binding of the dynamic-object.

提交回复
热议问题