/// <summary> /// 初始化所有实体 /// </summary> /// <param name="dicConfigs"></param> internal static void InitAllEntity(Dictionary <string, EntityConfigInfo> dicConfigs) { Queue <EntityInfoHandle> queEntitys = new Queue <EntityInfoHandle>(); foreach (KeyValuePair <string, EntityConfigInfo> item in dicConfigs) { EntityConfigInfo info = item.Value; if (info.Type != null) { queEntitys.Enqueue(InitEntityPropertyInfos(info.Type, dicConfigs)); } } EntityProxyBuilder proxyBuilder = new EntityProxyBuilder(); while (queEntitys.Count > 0) { EntityInfoHandle handle = queEntitys.Dequeue(); handle.InitProxyType(proxyBuilder); _dicClass[handle.ProxyType.FullName] = handle; } }
/// <summary> /// 填充类信息 /// </summary> /// <param name="dicParam">字段</param> /// <param name="dicRelation">关系</param> private static void FillEntityInfos(Dictionary <string, EntityParam> dicParam, Dictionary <string, TableRelationAttribute> dicRelation, Type type, TableAttribute tableAtt, Dictionary <string, EntityConfigInfo> dicConfigs) { string key = type.FullName; Stack <XmlDocument> stkXml = new Stack <XmlDocument>();//配置栈 EntityConfigInfo curConfig = null; if (!dicConfigs.TryGetValue(key, out curConfig)) { throw new Exception("找不到类:" + key + "所属的配置文件"); } XmlDocument docCur = curConfig.ConfigXML; FillEntityInfo(docCur, tableAtt); stkXml.Push(docCur); Type baseType = type.BaseType; List <TableRelationAttribute> lstSetAtt = new List <TableRelationAttribute>(); List <EntityParam> lstepAtt = new List <EntityParam>(); object[] attRels = type.GetCustomAttributes(false); foreach (object objAtt in attRels) { TableRelationAttribute tr = objAtt as TableRelationAttribute; if (tr != null) { lstSetAtt.Add(tr); continue; } EntityParam ep = objAtt as EntityParam; if (ep != null) { lstepAtt.Add(ep); continue; } } while (baseType != null && !IsSysBaseType(baseType)) //填充父类配置 { EntityConfigInfo config = null; string baseKey = null; if (baseType.IsGenericType) { baseKey = baseType.GetGenericTypeDefinition().FullName; } else { baseKey = baseType.FullName; } if (dicConfigs.TryGetValue(baseKey, out config)) { stkXml.Push(config.ConfigXML); } baseType = baseType.BaseType; } while (stkXml.Count > 0) { XmlDocument doc = stkXml.Pop(); //初始化属性 FillPropertyInfo(doc, dicParam); FillRelationInfo(doc, dicRelation); } foreach (TableRelationAttribute tra in lstSetAtt) { dicRelation[tra.FieldName] = tra; } foreach (EntityParam ep in lstepAtt) { dicParam[ep.FieldName] = ep; } }