private static object Convert(Type type, IList <IFieldable> fieldList) { int columnCount = fieldList.Count; object obj = DynamicClassEx.CreateInstance(type); foreach (IFieldable field in fieldList) { string columnName = field.Name; string value = field.StringValue; DynamicClassEx.SetPropertyValue(obj, columnName, value); } return(obj); }
/// <summary> /// 将Luncene中查询出来的文档列表转换成为对象列表 /// </summary> /// <param name="documentList"></param> /// <returns></returns> public static List <object> Convert(Dictionary <Document, ScoreDoc> documentList) { List <object> objectList = new List <object>(); if (documentList != null) { Dictionary <Document, ScoreDoc> .KeyCollection keys = documentList.Keys; foreach (Document document in keys) { IList <IFieldable> fieldList = document.GetFields(); Type type = DynamicClassEx.BuildType("DocumentType"); List <DynamicClassEx.CustomerPropertyInfo> lcpi = new List <DynamicClassEx.CustomerPropertyInfo>(); foreach (IFieldable field in fieldList) { DynamicClassEx.CustomerPropertyInfo cpi = new DynamicClassEx.CustomerPropertyInfo("System.Object", field.Name); lcpi.Add(cpi); } type = DynamicClassEx.AddProperty(type, lcpi); objectList.Add(Convert(type, fieldList)); } } return(objectList); }