/// <summary> /// Parse a XElement type parameter to a ComplexTypeElement instance. /// </summary> /// <param name="complexTypeElement">A ComplexType element.</param> /// <returns>Returns a ComplexTypeElement instance.</returns> public static ComplexTypeElement Parse(XElement complexTypeElement) { if (null == complexTypeElement) { return(null); } string name = null != complexTypeElement.Attribute("Name") ? complexTypeElement.Attribute("Name").Value : null; var props = new List <PropertyElement>(); string xPath = "./*[local-name()='Property']"; var propertyElements = complexTypeElement.XPathSelectElements(xPath, ODataNamespaceManager.Instance); foreach (var propEle in propertyElements) { if (null != propEle.Attribute("Name") && null != propEle.Attribute("Type")) { AnnotationDVsManager accessor = AnnotationDVsManager.Instance(); string propertyName = string.Format("{0}_{1}", name, propEle.GetAttributeValue("Name")); object defaultValue = accessor.GetDefaultValue(propertyName); bool nullable = null != propEle.Attribute("Nullable") ? Convert.ToBoolean(propEle.Attribute("Nullable").Value) : true; props.Add(new PropertyElement(propEle.Attribute("Name").Value.ToString(), propEle.Attribute("Type").Value.ToString(), defaultValue, nullable)); } } return(new ComplexTypeElement(name, props)); }
/// <summary> /// Parse a XElement type parameter to a TermElement type instance. /// </summary> /// <param name="termElement">The term element in metadata document.</param> /// <param name="getAliasAndNamespace">The delegate method which is used to get the alias and namespace of the term.</param> /// <returns>Return a TermElement type instance.</returns> public static TermElement Parse(XElement termElement, Func <XElement, AliasNamespacePair> getAliasAndNamespace) { var aliasNamespace = getAliasAndNamespace(termElement); string name = null != termElement.Attribute("Name") ? termElement.Attribute("Name").Value : null; string alias = aliasNamespace.Alias; string nspace = aliasNamespace.Namespace; string type = null != termElement.Attribute("Type") ? termElement.Attribute("Type").Value : null; string[] appliesTo = null != termElement.Attribute("AppliesTo") ? termElement.Attribute("AppliesTo").Value.Split(' ') : null; AnnotationDVsManager accessor = AnnotationDVsManager.Instance(); object defaultValue = accessor.GetDefaultValue(name); return(new TermElement(aliasNamespace, name, type, appliesTo, defaultValue)); }