我的问题是:如何制作标签?
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)和数据库操作。
GetValue
已经会返回正确类型的 值。你想做什么? - Thom Smith