场景假设:请结合自身情况修改!
假设有两个集合,集合类型分别是【PhysicalResult】和【PhysicalSummary】
IEnumerable<PhysicalResult> results = Current.Where(resultfilter).OrderBy(a =>a.CompositeItem.Id).ToList();
IEnumerable<PhysicalSummary> summaries = Current.Where(a => a.Summary != null).OrderBy(a => a.Id).ToList();
添加到List[]中
IList[] list = new IList[]{results.ToList(), summaries.ToList()};
若想取出类型为【PhysicalResult】的数据集合
方案一:
foreach (var item in list)
{
Type type = item.GetType();
if (type.IsGenericType)//是否是泛型
{
Type[] genericTypes = type.GetGenericArguments();//获取类名
string ClassName = genericTypes[0].Name;
if (ClassName == "IPhysicalResult")
{
results = item as List<IPhysicalResult>;
}
else if (ClassName == "IPhysicalSummary")
{
summaryLists = item as List<IPhysicalSummary>;
}
}
}
方案二:
IList<PhysicalResult> results = list.CastAs<IList<PhysicalResult>>().FirstOrDefault();
IList<PhysicalSummary> summaryLists = list.CastAs<IList<PhysicalSummary>.().FirstOrDefault();