How to iterate the List in Reflection

后端 未结 5 1997
粉色の甜心
粉色の甜心 2020-12-06 17:21

I am having one property called Students which is of type List.

In reflection i can get the value of Students Property.

Now the p

5条回答
  •  粉色の甜心
    2020-12-06 17:58

    Others have suggested casting to List but I will assume that this won't work for you... if you had access to the Student class, you wouldn't be using reflection to begin with. So instead, just cast to IEnumerable and then inside your loop, you'll have to use reflection again to access whatever properties you want off of each item in the collection.

    var collection = (IEnumerable)studentPro.GetValue(studentObj,null)

提交回复
热议问题