我的问题是:如何使
PropertyInfo.GetValue(object, null);
返回值转换为 PropertyType,而不是返回对象。
我试过 Convert.ChangeType 但不是运气。
谢谢你。
更新1:
更多详情:
我的代码:
foreach (var propertyInfo in customerInfo.CustomerRelationship.GetType().GetProperties())
{
var relationshipList = (IList)propertyInfo.GetValue(customerInfo.CustomerRelationship, null);
foreach (var relationship in relationshipList)
{
}
}
和
public struct CustomerInfo
{
public Customer CustomerItem { get; set; }
public Relationship CustomerRelationship { get; set; }
}
public class Relationship
{
public List<Contact> ContactItems { get; set; }
public List<Department> DepartmentItems { get; set; }
..........
}
因为我不能动态转换每个我无法比较的关系项目显示,所以查询(Linq)使用数据库进行操作。