Is there an easy way to convert object properties to a dictionary

后端 未结 4 1163
陌清茗
陌清茗 2020-12-28 13:23

I have a database object (a row), that has lots of properties (columns) that map to form fields (asp:textbox, asp:dropdownlist etc). I would like to transform this

4条回答
  •  孤城傲影
    2020-12-28 14:09

    Take a look at System.ComponentModel.TypeDescriptor.GetProperties( ... ). This is the way the normal data binding bits work. It will use reflection and return you a collection of property descriptors (which you can use to get the values). You can customize these descriptors for performace by implementing ICustomTypeDescriptor .

提交回复
热议问题