How to set a property of a C# 4 dynamic object when you have the name in another variable

后端 未结 5 547
独厮守ぢ
独厮守ぢ 2021-02-01 13:38

I\'m looking for a way to modify properties on a dynamic C# 4.0 object with the name of the property known only at runtime.

Is there a way to do something l

5条回答
  •  一向
    一向 (楼主)
    2021-02-01 14:08

    My open source framework Dynamitey has methods for invoking based on string names using the DLR. It does the work of caching binding sites and streamlines it down to one method call. it also runs faster than reflection on non-dynamic objects too.

    Dynamic.InvokeSet(e, "TestKey", "value");
    

提交回复
热议问题