Get string name of property using reflection

前端 未结 7 932
北海茫月
北海茫月 2020-11-28 06:56

There is a whole wealth of reflection examples out there that allow you to get either:

    1. All properties in a class

    2. A single property, provided you kn

7条回答
  •  悲哀的现实
    2020-11-28 07:39

    myClassInstance.GetType().GetProperties() gives you PropertyInfo instances for all public properties for myClassInstance's type. (See MSDN for documentation and other overloads.) ´PropertyInfo.Name´ is the actual name of the property. In case you already know the name of the property use GetProperty(name) to retrieve its PropertyInfo object (see MSDN again).

提交回复
热议问题