private static void ReadOracle(DbDataReader reader, string a, Dictionary <string, object> dic) { var id = reader.GetOrdinal(a.ToUpper()); var typeName = reader.GetDataTypeName(id).ToLower(); if (typeName == "clob" || typeName == "nclob") { var temp = BaseEmit.Invoke(reader, reader.GetType().GetMethod("GetOracleClob"), new object[] { id }); dic.Add(a.ToLower(), BaseEmit.Get(temp, "Value")); BaseEmit.Invoke(temp, temp.GetType().GetMethod("Close"), null); BaseEmit.Invoke(temp, temp.GetType().GetMethod("Dispose"), null); } else if (typeName == "blob") { var temp = BaseEmit.Invoke(reader, reader.GetType().GetMethod("GetOracleBlob"), new object[] { id }); dic.Add(a.ToLower(), BaseEmit.Get(temp, "Value")); BaseEmit.Invoke(temp, temp.GetType().GetMethod("Close"), null); BaseEmit.Invoke(temp, temp.GetType().GetMethod("Dispose"), null); } else { dic.Add(a.ToLower(), reader[a]); } }
/// <summary> /// 对象映射 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="model"></param> /// <returns></returns> public static T CopyModel <T, T1>(T1 model, Expression <Func <T1, object> > field = null) where T : class, new() { var result = new T(); var list = BaseDic.PropertyInfo <T>(); var dic = new Dictionary <MemberInfo, Expression>(); if (field != null) { var name = (field.Body as NewExpression).Members.ToList(); var value = (field.Body as NewExpression).Arguments.ToList(); for (var i = 0; i < name.Count; i++) { dic.Add(name[i], value[i]); } } BaseDic.PropertyInfo <T1>().ForEach(m => { if (list.Exists(a => string.Compare(a.Name, m.Name, true) == 0)) { var property = list.Find(a => string.Compare(a.Name, m.Name, true) == 0); var isList = m.PropertyType.GetGenericArguments().Length > 0; var isLeafSystemType = isList && m.PropertyType.GetGenericArguments()[0].FullName.StartsWith("System."); var isSystemType = m.PropertyType.FullName.StartsWith("System."); if (isList && !isLeafSystemType) { var leafList = Activator.CreateInstance(typeof(List <>).MakeGenericType(property.PropertyType.GetGenericArguments()[0])); var tempList = Convert.ChangeType(BaseEmit.Get <T1>(model, m.Name), m.PropertyType) as IEnumerable; if (tempList != null) { foreach (var temp in tempList) { var leafModel = Activator.CreateInstance(property.PropertyType.GetGenericArguments()[0]); var propertyList = leafModel.GetType().GetProperties().ToList(); temp.GetType().GetProperties().ToList().ForEach(p => { if (propertyList.Exists(a => a.Name == p.Name)) { var tempProperty = propertyList.Find(a => string.Compare(a.Name, p.Name, true) == 0); tempProperty.SetValue(leafModel, p.GetValue(temp)); } }); var method = leafList.GetType().GetMethod("Add", BindingFlags.Instance | BindingFlags.Public); BaseEmit.Invoke(leafList, method, new object[] { leafModel }); } BaseEmit.Set <T>(result, property.Name, leafList); } } else if (isSystemType) { BaseEmit.Set <T>(result, property.Name, BaseEmit.Get <T1>(model, m.Name)); } else { var tempModel = Convert.ChangeType(BaseEmit.Get <T1>(model, m.Name), m.PropertyType); var leafModel = Activator.CreateInstance(property.PropertyType); var propertyList = (property.PropertyType as TypeInfo).GetProperties().ToList(); (m.PropertyType as TypeInfo).GetProperties().ToList().ForEach(p => { if (propertyList.Exists(a => a.Name == p.Name)) { var temp = propertyList.Find(a => string.Compare(a.Name, p.Name, true) == 0); temp.SetValue(leafModel, p.GetValue(tempModel)); } }); BaseEmit.Set <T>(result, property.Name, leafModel); } } else { if (dic.ToList().Exists(n => string.Compare((n.Value as MemberExpression).Member.Name, m.Name, true) == 0)) { var temp = dic.ToList().Find(n => string.Compare((n.Value as MemberExpression).Member.Name, m.Name, true) == 0); BaseEmit.Set <T>(result, temp.Key.Name, BaseEmit.Get <T1>(model, (temp.Value as MemberExpression).Member.Name)); } } }); return(result); }