Exposing properties of an ExpandoObject

后端 未结 2 1138
迷失自我
迷失自我 2020-12-17 23:41

I\'ve got an ExpandoObject that I\'m sending to an external library method which takes an object. From what I\'ve seen this external lib uses TypeDescriptor.GetProperties in

2条回答
  •  眼角桃花
    2020-12-17 23:56

    The only way I could get the OP's code to work with Marc's ExpandoTypeDescriptor code was to modify the OP's call to GetTypeDescriptor, casting the return value to ExpandoObject.

    public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance)
    {
         var defaultDescriptor = base.GetTypeDescriptor(objectType, instance);
    
         return instance == null ? defaultDescriptor :
                new ExpandoTypeDescriptor((ExpandoObject)instance);
    }
    

提交回复
热议问题