/// <summary> /// 获取所有的模块类型集合 /// </summary> /// <returns></returns> public static List <Type> GetAllModelTypes() { List <Type> tempTypes = new List <Type>(); if (cacheFactory != null && cacheFactory.Exists(cache_modelType)) { tempTypes = cacheFactory.Get <List <Type> >(cache_modelType); if (tempTypes == null) { tempTypes = new List <Type>(); } return(tempTypes); } string modelDll = DEFAULT_MODEL_DLL; //默认实体层dll //取自定义数据模型类型 string customerModelBLL = WebConfigHelper.GetAppSettingValue("Model"); if (!string.IsNullOrEmpty(customerModelBLL)) { modelDll += string.Format(",{0}", customerModelBLL); } NotNullCheck.NotEmpty(modelDll, "Web.config->appSettings中实体层程序集名称"); List <Type> types = new List <Type>(); if (!string.IsNullOrEmpty(modelDll)) { string[] token = modelDll.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (string dllName in token) { types.AddRange(GetTypesByDLL(dllName)); } } //添加临时实体类型集合 List <Type> tempModelTypes = GetTempModelTypes(); types.AddRange(tempModelTypes); //取模块类型集合 foreach (Type type in types) { ModuleConfigAttribute moduleConfig = ((ModuleConfigAttribute)(Attribute.GetCustomAttribute(type, typeof(ModuleConfigAttribute)))); NoModuleAttribute noModuleAttr = ((NoModuleAttribute)(Attribute.GetCustomAttribute(type, typeof(NoModuleAttribute)))); if (moduleConfig == null && noModuleAttr == null) { continue; } tempTypes.Add(type); } if (tempTypes.Count > 0 && cacheFactory != null) { cacheFactory.Set <List <Type> >(cache_modelType, tempTypes); } return(tempTypes); }
/// <summary> /// 获取实体类型 /// </summary> /// <param name="moduleName">模块名称</param> /// <returns></returns> public static Type GetModelTypeByModuleName(string moduleName) { List <Type> types = GetAllModelTypes(); foreach (Type type in types) { ModuleConfigAttribute moduleConfig = ((ModuleConfigAttribute)(Attribute.GetCustomAttribute(type, typeof(ModuleConfigAttribute)))); if (moduleConfig != null && moduleConfig.Name == moduleName) { return(type); } } return(null); }