public static JoinPropertyNode Create(ClassNode info, XElement property) { string name = null, target, attribuleValue; if(MappingInfo.GetAttribuleValue(property, "name", out attribuleValue)) name = attribuleValue; else throw new FormatException(string.Format("{0}.property节点name属性未赋值", info.Name)); if(MappingInfo.GetAttribuleValue(property, "relationTo", out attribuleValue)) target = attribuleValue; else throw new FormatException(string.Format("{0}.property节点relationTo属性未赋值", info.Name)); var joinPropertyInfo = new JoinPropertyNode(name, target); var join = property.Element("join"); if(MappingInfo.GetAttribuleValue(join, "mode", out attribuleValue)) { JoinType temp; joinPropertyInfo._type = Zongsoft.Common.Convert.TryConvertValue<JoinType>(attribuleValue, out temp) ? temp : JoinType.Inner; } foreach(var relation in join.Elements()) { string from, to; if(MappingInfo.GetAttribuleValue(relation, "from", out attribuleValue)) from = attribuleValue; else throw new FormatException(string.Format("{0}.property节点中有member项from属性未赋值", info.Name)); if(MappingInfo.GetAttribuleValue(relation, "to", out attribuleValue)) to = attribuleValue; else throw new FormatException(string.Format("{0}.property节点中有member项to属性未赋值", info.Name)); joinPropertyInfo.Add(from, to); } return joinPropertyInfo; }
public static PropertyNode Create(XElement property) { string propertyInfoName = null, attribuleValue; if (MappingInfo.GetAttribuleValue(property, "name", out attribuleValue) || !(attribuleValue = property.Name.LocalName).Equals("property", StringComparison.OrdinalIgnoreCase)) { propertyInfoName = attribuleValue; } var propertyInfo = new PropertyNode(propertyInfoName); if (MappingInfo.GetAttribuleValue(property, "constructor.parameter", out attribuleValue)) { propertyInfo._parameterName = attribuleValue; propertyInfo._passedIntoConstructor = true; } if (property.Attribute("field") == null) { propertyInfo._field = propertyInfo.Name; } else if (MappingInfo.GetAttribuleValue(property, "field", out attribuleValue)) { propertyInfo._field = attribuleValue; } else { propertyInfo._ignored = true; } if (MappingInfo.GetAttribuleValue(property, "sequenced", out attribuleValue)) { propertyInfo._sequenced = true; } return(propertyInfo); }
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); }