Reflection class to get all properties of any object

后端 未结 3 2019
眼角桃花
眼角桃花 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 20:54

    Your propertyInfos array is returning 0 length for one of my classes. Changing the line to be

    propertyInfos = thisObject.GetType().GetProperties();
    

    Results in it being populated. Therefore, this line of code is your problem. It appears if you add the flag

    BindingFlags.Instance
    

    to your parameters it will return the same properties as the parameterless call. Does adding this parameter to your list fix the problem?

    EDIT: Just saw your edit. Based on the code you posted, it didn't work for me either. Adding the BindingFlags.Instance made it return properties for me. I'd suggest posting the exact code you are having trouble with as your screenshot shows different code.

提交回复
热议问题