Ejemplo n.º 1
0
 /// <summary>
 /// 注册程序集。
 /// </summary>
 /// <param name="assembly"></param>
 /// <returns></returns>
 public System.Collections.Generic.List <DatabaseSchemaHandler> RegisterAssembly(System.Reflection.Assembly assembly)
 {
     System.Collections.Generic.List <DatabaseSchemaHandler> list = new System.Collections.Generic.List <DatabaseSchemaHandler>();
     if (assembly == null ||
         assembly.FullName.StartsWith("System") ||
         assembly.FullName.StartsWith("mscorlib")
         //|| assembly.IsDynamic
         )
     {
         return(list);
     }
     _log.Info("反射程序集:{0}", assembly.FullName);
     System.Type[] types;
     try {
         types = assembly.GetExportedTypes();
     } catch (System.Exception error) {
         _log.Warning("反射程序集失败:{0}\r\n{1}", assembly.FullName, LogBase.ExceptionToString(error));
         return(list);
     }
     foreach (System.Type type in types)
     {
         DatabaseSchemaHandler item = RegisterType(type);
         if (item == null)
         {
             continue;
         }
         list.Add(item);
     }
     return(list);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 注册类型。
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public DatabaseSchemaHandler RegisterType(System.Type type)
        {
            if (type == null || !type.IsClass || type.IsAbstract ||
                !TypeExtensions.IsInheritFrom(type, typeof(DatabaseSchemaHandler)))
            {
                return(null);
            }
            DatabaseSchemaHandler handler = null;
            string key = type.FullName;

            if (_caches.TryGetValue(key, out handler))
            {
                return(handler);
            }
            string fullName = TypeExtensions.FullName2(type);

            try {
                _log.Info("创建实例:{0}", fullName);
                handler = (DatabaseSchemaHandler)FastWrapper.CreateInstance(type);
                _caches.Add(key, handler);
                _list.Add(handler);
                ClassOrder(handler.Attribute.TableName, handler.Attribute.Order);
                CacheRef(type.Assembly, handler);
                return(handler);
            } catch (System.Exception error) {
                _log.Warning("创建实例失败:{0}\r\n{1}", fullName, LogBase.ExceptionToString(error));
                return(null);
            }
        }
Ejemplo n.º 3
0
        void CacheRef(System.Reflection.Assembly assembly, DatabaseSchemaHandler handler)
        {
            AssemblyRef item;
            string      fullName = assembly.FullName;

            if (_refs.TryGetValue(fullName, out item))
            {
                item.list.Add(handler);
                return;
            }
            item = new AssemblyRef()
            {
                fullName = assembly.FullName,
                refs     = LinqHelper.ToArray(LinqHelper.Select(assembly.GetReferencedAssemblies(), p => p.FullName)),
                list     = new System.Collections.Generic.List <DatabaseSchemaHandler>(),
            };
            item.list.Add(handler);
            _refs.Add(fullName, item);
        }