Reflection class to get all properties of any object

后端 未结 3 2033
眼角桃花
眼角桃花 2020-12-31 20:14

I need to make a function that get all the properies of an object (including an children objects) This is for my error logging feature. Right now my code always returns 0 pr

3条回答
  •  执笔经年
    2020-12-31 21:15

    If you want all of the properties, try:

    propertyInfos = thisObject.GetType().GetProperties(
          BindingFlags.Public | BindingFlags.NonPublic // Get public and non-public
        | BindingFlags.Static | BindingFlags.Instance  // Get instance + static
        | BindingFlags.FlattenHierarchy); // Search up the hierarchy
    

    For details, see BindingFlags.

提交回复
热议问题