-1

I have a List<T> of element and a PropertyInfo with a list of the property of T.

How can I identify a single property of an element in a loop ?

Ideally :

List<T>[i].PropertyInfo[y].Name
Nimantha
  • 6,405
  • 6
  • 28
  • 69
  • 1
    possible duplicate of [Using reflection to get values from properties from a list of a class](http://stackoverflow.com/questions/10710156/using-reflection-to-get-values-from-properties-from-a-list-of-a-class) – Michael Edenfield Feb 21 '15 at 11:54
  • No. I read the post you have mentioned. My problem is different. I have a Generic List of element and the array of its properties. No nested classes. I want only to get to enumerate all the element of the list with its properties using the infos I have. – Simone Spagna Feb 21 '15 at 12:08
  • 1
    is that not what the accepted answer does? you cast your list to an `IList`, use foreach on it (or use the `Item` method), and use your propertyinfos to get each value? That's as good as it gets, I think... – Michael Edenfield Feb 21 '15 at 12:45

3 Answers3

0

If you are looking for the type of the properties, you must use the property:

PropertyInfo.PropertyType
Leonardo Festa
  • 101
  • 1
  • 6
0

If i understood the question currently and you're looking to match the two collections, then you could use the type of the property info(Has a property type Property) and the typeof(T). For efficiency i would recommend creating a dynamic method that would be cached for future usage.

Roman Ambinder
  • 369
  • 3
  • 7
0

I solved the problem using a solution like the one in the post "Get property value from string using reflection in C#".

Nimantha
  • 6,405
  • 6
  • 28
  • 69