/// <summary> /// 加载自定义标签 /// </summary> /// <param name="BusinessDll">Dll路径</param> /// <param name="cache">存入缓存</param> public static void LoadAttribute(List <Assembly> BusinessDll, ICacheManager cache, string pluginName) { string cacheKey = pluginName + "@" + GetCacheKey(); List <EntityAttributeInfo> entityAttributeList = new List <EntityAttributeInfo>(); for (int k = 0; k < BusinessDll.Count; k++) { System.Reflection.Assembly assembly = BusinessDll[k]; //System.Reflection.Assembly.LoadFrom(BusinessDll[k]); Type[] types = assembly.GetTypes(); for (int i = 0; i < types.Length; i++) { TableAttribute[] tableAttrs = ((TableAttribute[])types[i].GetCustomAttributes(typeof(TableAttribute), true)); if (tableAttrs.Length > 0) { EntityAttributeInfo eattr = new EntityAttributeInfo(); eattr.ObjType = types[i]; eattr.TableAttributeInfoList = new List <TableAttributeInfo>(); foreach (TableAttribute val in tableAttrs) { TableAttributeInfo tableattr = new TableAttributeInfo(); tableattr.Alias = val.Alias; tableattr.EType = val.EntityType; tableattr.TableName = val.TableName; tableattr.IsGB = val.IsGB; tableattr.ColumnAttributeInfoList = new List <ColumnAttributeInfo>(); PropertyInfo[] property = eattr.ObjType.GetProperties(); for (int n = 0; n < property.Length; n++) { ColumnAttribute[] columnAttributes = (ColumnAttribute[])property[n].GetCustomAttributes(typeof(ColumnAttribute), true); if (columnAttributes.Length > 0) { ColumnAttributeInfo colattr = new ColumnAttributeInfo(); ColumnAttribute colval = columnAttributes.ToList().Find(x => x.Alias == tableattr.Alias); if (colval == null) { throw new Exception("输入的Alias别名不正确"); } colattr.Alias = colval.Alias; colattr.DataKey = colval.DataKey; colattr.FieldName = colval.FieldName; colattr.IsInsert = colval.IsInsert; //colattr.IsSingleQuote=colval.is colattr.Match = colval.Match; colattr.PropertyName = property[n].Name; if (colattr.DataKey) { tableattr.DataKeyFieldName = colattr.FieldName;//设置TableAttributeInfo的主键字段名 tableattr.DataKeyPropertyName = colattr.PropertyName; } tableattr.ColumnAttributeInfoList.Add(colattr); } } eattr.TableAttributeInfoList.Add(tableattr); } entityAttributeList.Add(eattr); } } } cache.Add(cacheKey, entityAttributeList); }
/// <summary> /// 加载自定义标签 /// </summary> /// <param name="BusinessDll">Dll路径</param> /// <param name="cache">存入缓存</param> public static void LoadAttribute(List<string> BusinessDll, ICacheManager cache,string pluginName) { string cacheKey = pluginName+"@"+GetCacheKey(); List<EntityAttributeInfo> entityAttributeList = new List<EntityAttributeInfo>(); for (int k = 0; k < BusinessDll.Count; k++) { System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(BusinessDll[k]); Type[] types = assembly.GetTypes(); for (int i = 0; i < types.Length; i++) { TableAttribute[] tableAttrs = ((TableAttribute[])types[i].GetCustomAttributes(typeof(TableAttribute), true)); if (tableAttrs.Length > 0) { EntityAttributeInfo eattr = new EntityAttributeInfo(); eattr.ObjType = types[i]; eattr.TableAttributeInfoList = new List<TableAttributeInfo>(); foreach (TableAttribute val in tableAttrs) { TableAttributeInfo tableattr = new TableAttributeInfo(); tableattr.Alias = val.Alias; tableattr.EType = val.EntityType; tableattr.TableName = val.TableName; tableattr.IsGB = val.IsGB; tableattr.ColumnAttributeInfoList = new List<ColumnAttributeInfo>(); PropertyInfo[] property = eattr.ObjType.GetProperties(); for (int n = 0; n < property.Length; n++) { ColumnAttribute[] columnAttributes = (ColumnAttribute[])property[n].GetCustomAttributes(typeof(ColumnAttribute), true); if (columnAttributes.Length > 0) { ColumnAttributeInfo colattr = new ColumnAttributeInfo(); ColumnAttribute colval = columnAttributes.ToList().Find(x => x.Alias == tableattr.Alias); if (colval == null) throw new Exception("输入的Alias别名不正确"); colattr.Alias = colval.Alias; colattr.DataKey = colval.DataKey; colattr.FieldName = colval.FieldName; colattr.IsInsert = colval.IsInsert; //colattr.IsSingleQuote=colval.is colattr.Match = colval.Match; colattr.PropertyName = property[n].Name; if (colattr.DataKey) { tableattr.DataKeyFieldName = colattr.FieldName;//设置TableAttributeInfo的主键字段名 tableattr.DataKeyPropertyName = colattr.PropertyName; } tableattr.ColumnAttributeInfoList.Add(colattr); } } eattr.TableAttributeInfoList.Add(tableattr); } entityAttributeList.Add(eattr); } } } cache.Add(cacheKey, entityAttributeList); }