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

后端 未结 5 1044
忘掉有多难
忘掉有多难 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:59

    If you want an end to end sample including source code, resulting in a dynamic object that stores value for arbitrary properties in a Dictionary then my post "A first look at Duck Typing in C# 4.0" could be right for you. I wrote that post to show how dynamic object can be cast to statically typed interfaces. It has a complete working implementation of a Duck that is a IDynamicObject and may acts like a IQuack.

    If you need more information contact me on my blog and I will help you along, as good as I can.

提交回复
热议问题