public void Init(ClassNode host, List<ClassNode> all) { if(_target == null) { _target = all.FirstOrDefault(p => p.Name.Equals(_targetStr, StringComparison.OrdinalIgnoreCase)); if(_target == null) throw new Exception(string.Format("未找到{0}对应的节点,source:{1},join:{1}", _targetStr, host.Name, _name)); } if(_member==null) _member = new Dictionary<PropertyNode, PropertyNode>(); foreach(var key in _temp.Keys) { var fromPropertyInfo = host.PropertyNodeList.FirstOrDefault(p => p.Name.Equals(key, StringComparison.OrdinalIgnoreCase)); if(fromPropertyInfo == null) { fromPropertyInfo = new PropertyNode(key); host.AddPropertyNodel(fromPropertyInfo); } var value = _temp[key]; var toPropertyInfo = _target.PropertyNodeList.FirstOrDefault(p => p.Name.Equals(value, StringComparison.OrdinalIgnoreCase)); if(toPropertyInfo == null) { toPropertyInfo = new PropertyNode(value); _target.AddPropertyNodel(toPropertyInfo); } _member.Add(fromPropertyInfo, toPropertyInfo); } }
public static ClassNode Create(XElement element) { string attribuleValue; var info = new ClassNode(); if (MappingInfo.GetAttribuleValue(element, "type", out attribuleValue)) { info._typeStr = attribuleValue; } if (MappingInfo.GetAttribuleValue(element, "name", out attribuleValue) || !(attribuleValue = element.Name.LocalName).Equals("object", StringComparison.OrdinalIgnoreCase)) { info._name = attribuleValue; } else { info._name = info.EntityType.Name; } if (MappingInfo.GetAttribuleValue(element, "table", out attribuleValue)) { info._table = attribuleValue; } if (MappingInfo.GetAttribuleValue(element, "schema", out attribuleValue)) { info._schema = attribuleValue; } if (MappingInfo.GetAttribuleValue(element, "inherits", out attribuleValue)) { info._inherit = attribuleValue; } info._propertyNodeList = new List <PropertyNode>(); info._joinList = new List <JoinPropertyNode>(); foreach (var property in element.Elements()) { if (property.Name.LocalName.Equals("key", StringComparison.OrdinalIgnoreCase)) { foreach (var key in property.Elements()) { var keyPropertyInfo = PropertyNode.Create(key); if (string.IsNullOrWhiteSpace(keyPropertyInfo.Name)) { throw new FormatException(string.Format("{0}节点下面有一个主键没有name属性", info.Name)); } keyPropertyInfo.IsKey = true; info.AddPropertyNodel(keyPropertyInfo); } continue; } else if (property.HasElements) { var joinPropertyInfo = JoinPropertyNode.Create(info, property); info.JoinList.Add(joinPropertyInfo); continue; } var propertyInfo = PropertyNode.Create(property); if (string.IsNullOrWhiteSpace(propertyInfo.Name)) { throw new FormatException(string.Format("{0}节点下面有一个property节点没有name属性", info.Name)); } info.AddPropertyNodel(propertyInfo); } return(info); }