/// <summary> /// Adds an XML specific representation annotation to the specified ODataPayloadElement. /// </summary> /// <typeparam name="TElement">The type of the payload element to work on.</typeparam> /// <param name="payloadElement">The payload element to annotate.</param> /// <param name="xmlNodes">The XML nodes to annotate with.</param> /// <returns>The annotated payload element, for composability.</returns> public static TElement XmlRepresentation <TElement>(this TElement payloadElement, IEnumerable <XNode> xmlNodes) where TElement : ODataPayloadElement { ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement"); ExceptionUtilities.CheckArgumentNotNull(xmlNodes, "xmlNodes"); var annotation = new XmlPayloadElementRepresentationAnnotation { XmlNodes = xmlNodes }; payloadElement.SetAnnotation(annotation); return(payloadElement); }
/// <summary> /// Deserialize a single link /// </summary> /// <param name="link">the xml representing the link</param> /// <returns>Either an expanded or deferred link</returns> private ODataPayloadElement DeserializeLink(XElement link) { if (link.Name == MetadataUri) { var result = new DeferredLink() { UriString = link.Attribute(AtomId).Value }; AddXmlBaseAnnotation(result, link); // add the element so that later validation can happen to validate the MetadataUri namespace is not used var xmlPayloadRep = new XmlPayloadElementRepresentationAnnotation() { XmlNodes = new XNode[] { link } }; result.Annotations.Add(xmlPayloadRep); return result; } string hrefValue = null; XAttribute hrefAttribute = link.Attribute(Href); if (hrefAttribute != null) { if (string.IsNullOrEmpty(hrefAttribute.Value)) { // special case: navigation properties with null values are represented as empty href tags return null; } hrefValue = hrefAttribute.Value; } // if the link has an inline element, assume it is expanded XElement inline = link.Element(MetadataInline); if (inline != null) { // deserialize the expanded element ExpandedLink expanded = new ExpandedLink() { UriString = hrefValue }; if (inline.HasElements) { expanded.ExpandedElement = this.ConvertToPayloadElement(inline.Elements().Single()); } this.AddLinkAttributes(expanded, link); return expanded; } else { // otherwise it must be deferred DeferredLink deferred = new DeferredLink() { UriString = hrefValue }; this.AddLinkAttributes(deferred, link); return deferred; } }