Treat Object Like Dictionary of Properties in C#

后端 未结 3 1143
名媛妹妹
名媛妹妹 2020-12-14 19:35

I want to be able to access property values in an object like a dictionary, using the name of the property as a key. I don\'t really care if the values are returned as objec

3条回答
  •  不知归路
    2020-12-14 20:06

    dynamic keyword may be one option for you. it uses dynamic language runtime. At runtime, it tries to match the closest available type in the program. If it cant, then it converts the dynamic type to dictionay object, where key is the name of property and value is the value of property.

    follow these links of MSDN:

    Using dynamic keyword in C#
    dynamic (C# Reference)
    DLR Overview
    usage of dynamic sample walkthough page

提交回复
热议问题