public List<CariHesapEkstre> ConvertToDesiredType ( object list )
{
return ( (IEnumerable<dynamic>)list ).Select(item => new CariHesapEkstre
{
MutabakatDetayId = item.MutabakatDetayId,
MutabakatVar = item.MutabakatVar,
}).ToList();
}
方法二,直接映射
public static List<DispatchEntity> ConvertToDesiredType(object list)
{
List<DispatchEntity> returnList = new List<DispatchEntity>();
foreach (var item in (IEnumerable<dynamic>)list)
{
DispatchEntity obj =JsonConvert.DeserializeObject<DispatchEntity>(item.ToString().Replace("{{","{").Replace("}}","}"));
DispatchEntity extract = new DispatchEntity();
foreach (PropertyInfo prop in obj.GetType().GetProperties())
{
foreach (PropertyInfo prop2 in extract.GetType().GetProperties())
{
if (prop2.Name == prop.Name)
{
prop2.SetValue(extract, prop.GetValue(obj));
}
}
}
returnList.Add(extract);
}
return returnList;
}