提问人:Farzad Karimi 提问时间:11/21/2022 更新时间:11/21/2022 访问量:9
从反射中获取的转换列表
Converted List That Got From Reflection
问:
我使用反射得到一个列表,我想以这种方式用数据填充该列表:
public class SearchCriteria
{
public int SearchValue { get; set; }
public string SearchField { get; set; }
}
public class intListRequest
{
public List<SearchCriteria> SearchList { get; set; }
}
private static void ApplySearchList(intListRequest request)
{
Type type = typeof(intListRequest);
var propers = type.GetProperties();
var propsResult = propers.Where(a => a.Name == "intList");
var prop = propsResult.FirstOrDefault();
if (prop.PropertyType == typeof(List<int>))
{
List<int> newprop = prop.CastTo<List<int>>(); //**error here**//
newprop.Add(SearchValue1);
newprop.Add(SearchValue2);
newprop.Add(SearchValue3);
}
}
我的问题是我显示的行,如何将其转换为 int List?
答: 暂无答案
评论