简体   繁体   中英

How to Individuate an element of a list using reflection?

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

如果您正在寻找属性的类型,则必须使用该属性:

PropertyInfo.PropertyType

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.

我使用类似于“使用 C# 中的反射从字符串获取属性值”一文中的解决方案解决了该问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM