string className = "CustomerEntities[2]"
PropertyInfo propertyInfo = model.GetType().GetProperty(className);
propertyInfo始终为null,如何在列表的某个索引处选择类,即2.但是,如果我将类名更改为“CustomerEntities”,则会选择整个列表。
答案 0 :(得分:0)
你必须得到整个列表的值,然后从该列表中选择你想要的记录,这里是假设你“CustomerEntities”的类型为List
的例子。string className = "CustomerEntities";
PropertyInfo propertyInfo = model.GetType().GetProperty(className);
List<string> result = (List<string>) propertyInfo.GetValue(model);
string record = result[2];