public static IMapperEmit Build(Type klassSrc, Type klassDest) { if (cache == null) { cache = new CacheStructure(); } IMapperEmit mapper = cache.GetMapper(klassSrc, klassDest); if (mapper == null) { mapper = new MapperEmit(klassSrc, klassDest); cache.Add(klassSrc, klassDest, mapper); } return(mapper); }
public override void LinkMembers(string nameSrc, string nameDest) { FieldInfo fInfoSrc = src.GetField(nameSrc); FieldInfo fInfoDest = dest.GetField(nameDest); if (fInfoSrc != null && fInfoDest != null) { if (fInfoSrc.FieldType.IsAssignableFrom(fInfoDest.FieldType)) { fieldList.Add(new KeyValuePair <FieldInfo, FieldInfo>(fInfoSrc, fInfoDest)); } else if (!fInfoSrc.FieldType.IsPrimitive && !fInfoDest.FieldType.IsPrimitive && fInfoSrc.FieldType != typeof(string) && fInfoDest.FieldType != typeof(string)) { KeyValuePair <FieldInfo, FieldInfo> pair = new KeyValuePair <FieldInfo, FieldInfo>(fInfoSrc, fInfoDest); IMapperEmit m = new MapperEmit(fInfoSrc.FieldType, fInfoDest.FieldType); map.Add(pair, m); fieldList.Add(pair); } } }
public override void LinkMembers(string nameSrc, string nameDest) { PropertyInfo pInfoSrc = src.GetProperty(nameSrc); PropertyInfo pInfoDest = dest.GetProperty(nameDest); if (pInfoSrc != null && pInfoDest != null) { if (pInfoSrc.PropertyType.IsAssignableFrom(pInfoDest.PropertyType)) { propertyList.Add(new KeyValuePair <PropertyInfo, PropertyInfo>(pInfoSrc, pInfoDest)); } else if (!pInfoSrc.PropertyType.IsPrimitive && !pInfoDest.PropertyType.IsPrimitive && pInfoSrc.PropertyType != typeof(string) && pInfoDest.PropertyType != typeof(string)) { IMapperEmit m = new MapperEmit(pInfoSrc.PropertyType, pInfoDest.PropertyType); KeyValuePair <PropertyInfo, PropertyInfo> pair = new KeyValuePair <PropertyInfo, PropertyInfo>(pInfoSrc, pInfoDest); map.Add(pair, m); propertyList.Add(pair); } } }