public static MappingClass loadByReflection() { logger.Info("loadByReflection"); IList asmList = DbConfig.Instance.AssemblyList; MappingClass map = new MappingClass(); for (int i = 0; i < asmList.Count; i++) { Assembly assembly = ObjectContext.LoadAssembly(asmList[i].ToString()); map.AssemblyList[asmList[i].ToString()] = assembly; Type[] typeArray = ObjectContext.FindTypes(asmList[i].ToString()); foreach (Type type in typeArray) { ResolveOneType(map, type); } logger.Info("loaded assembly: " + assembly.FullName); } logger.Info("FinishPropertyInfo"); FinishPropertyInfo(map.ClassList); logger.Info("cacheInterceptor"); cacheInterceptor(map); logger.Info("AccessorUtil.Init"); MetaList list = new MetaList(map.AssemblyList, map.ClassList); map.FactoryList = AccessorUtil.Init(list); try { checkMultiDB(map); } catch (Exception ex) { logger.Info("初始化数据库出现错误:" + ex.Message); } return(map); }
public static Hashtable Init( MetaList metaList ) { logger.Info( "cacheFactory..." ); Hashtable factoryList = cacheFactory( metaList ); logger.Info( "cacheAccessor..." ); cacheAccessor( metaList ); return factoryList; }
public static IPropertyAccessor GetAccessor( String typeFullName, String propertyName, MetaList mapping ) { switch (DbConfig.Instance.OptimizeMode) { case OptimizeMode.CodeDom: return CodeDomPropertyAccessor.GetAccessor( typeFullName, propertyName, mapping ); case OptimizeMode.IL: return ILPropertyAccessor.GetAccessor( typeFullName, propertyName ); } return null; }
private static Hashtable cacheFactory( MetaList metas ) { if( DbConfig.Instance.OptimizeMode == OptimizeMode.CodeDom ) { CodeDomPropertyAccessor.Init( metas ); return CodeDomPropertyAccessor.GetFactoryList(); } else if( DbConfig.Instance.OptimizeMode == OptimizeMode.IL ) { ILPropertyAccessor.Init(); return null; } return null; }
private static void cacheAccessor( MetaList metas ) { foreach (DictionaryEntry entry in metas.ClassList) { String str = entry.Key.ToString(); EntityInfo info = entry.Value as EntityInfo; foreach (EntityPropertyInfo ep in info.PropertyListAll) { ep.PropertyAccessor = GetAccessor( info.Type.FullName, ep.Name, metas ); if (ep.PropertyAccessor == null) { throw new Exception( "PropertyAccessor can not be null : [type name]" + info.Type.FullName + ", [property name]" + ep.Name ); } } } }
public static IDictionary GetAccessorList( MetaList metaList ) { if (_accessorList == null) { IDictionary classList = metaList.ClassList; IDictionary asmList = metaList.AssemblyList; Assembly assembly = CompileCode( GetAccessorCode( classList ), asmList ); _accessorList = (assembly.CreateInstance( "System.Reflection.CodeDomAccessorUtil" ) as IAccessorUtil).GetAccessorList(); foreach (DictionaryEntry entry in classList) { String typeFullName = entry.Key.ToString(); IConcreteFactory factory = assembly.CreateInstance( getConcreteFactoryName( typeFullName ) ) as IConcreteFactory; _concreteFactoryList[typeFullName] = factory; } } return _accessorList; }
public static MappingClass loadByReflection() { logger.Info("通过反射机制加载程序集..."); IList asmList = DbConfig.Instance.AssemblyList; MappingClass map = new MappingClass(); try { for (int i = 0; i < asmList.Count; i++) { Assembly assembly = ObjectContext.LoadAssembly(asmList[i].ToString()); logger.Info("程序集: " + assembly.FullName); map.AssemblyList[asmList[i].ToString()] = assembly; Type[] typeArray = ObjectContext.FindTypes(asmList[i].ToString()); foreach (Type type in typeArray) { ResolveOneType(map, type); } } logger.Info("FinishPropertyInfo"); FinishPropertyInfo(map.ClassList); logger.Info("cacheInterceptor"); cacheInterceptor(map); logger.Info("AccessorUtil.Init"); MetaList list = new MetaList(map.AssemblyList, map.ClassList); map.FactoryList = AccessorUtil.Init(list); try { checkMultiDB(map); } catch (Exception ex) { logger.Info("初始化数据库出现错误:" + ex.Message); } } catch (Exception ex) { logger.Info("初始化Orm对象出现错误:" + ex.Message); } return map; }
public static IPropertyAccessor GetAccessor( String typeFullName, String propertyName, MetaList metaList ) { return (GetAccessorList( metaList )[getAccessorName( typeFullName, propertyName )] as IPropertyAccessor); }
public static void Init( MetaList metaList ) { GetAccessorList( metaList ); }