/// <summary> /// Visits the payload element /// </summary> /// <param name="payloadElement">The payload element to visit</param> public override void Visit(EntitySetInstance payloadElement) { ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement"); XmlRewriteElementAnnotation annotation = new XmlRewriteElementAnnotation() { RewriteFunction = (node) => { XNode foundNode = null; var currentNode = node.FirstNode; if (node.Nodes().Count() > 1) { while (currentNode != null && foundNode == null) { var element = (XElement)currentNode; if (element.Name.LocalName.Equals("id")) { foundNode = currentNode; currentNode.Remove(); } currentNode = currentNode.NextNode; } if (foundNode != null) { node.FirstNode.AddBeforeSelf(foundNode); } } return node; } }; payloadElement.Add(annotation); base.Visit(payloadElement); }
/// <summary> /// Adds an XML rewriting 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="rewriteFunction">The function that will be applied to the XML element that results from serializing the payload element</param> /// <returns>The annotated payload element, for composability.</returns> /// <returns></returns> public static TElement WithXmlRewriteFunction <TElement>(this TElement payloadElement, Func <XElement, XNode> rewriteFunction) where TElement : ODataPayloadElement { ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement"); var annotation = new XmlRewriteElementAnnotation { RewriteFunction = rewriteFunction }; payloadElement.SetAnnotation(annotation); return(payloadElement); }