/// <summary> /// Adds the name of the encoding to be used for serialization to the payload element. /// </summary> /// <param name="payloadElement">The payload element to add the encoding name to.</param> /// <param name="encodingName">The name of the encoding to be used for serialization.</param> /// <param name="omitDeclaration">true to omit the Xml declaration during serialization; otherwise false.</param> /// <returns>The <paramref name="payloadElement"/> with the encoding name annotation added.</returns> public static ODataPayloadElement SerializationEncoding( this ODataPayloadElement payloadElement, string encodingName, bool omitDeclaration) { return(payloadElement.AddAnnotation( new SerializationEncodingNameAnnotation { EncodingName = encodingName, OmitDeclaration = omitDeclaration, })); }
/// <summary> /// Annotates the <paramref name="payloadElement"/> with the format version if it's not already annotated. /// </summary> /// <param name="payloadElement">The payload element to annotate.</param> private void AddVersionAnnotation(ODataPayloadElement payloadElement) { PayloadFormatVersionAnnotation versionAnnotation = (PayloadFormatVersionAnnotation)payloadElement.GetAnnotation(typeof(PayloadFormatVersionAnnotation)); if (versionAnnotation == null) { versionAnnotation = new PayloadFormatVersionAnnotation() { Version = this.version, Response = !this.requestPayload, }; payloadElement.AddAnnotation(versionAnnotation); } }
/// <summary> /// Converts the Object Model representation of Atom link metadata into appropriate annotations for a payload element representing a link. /// </summary> /// <param name="linkMetadata">The Atom link metadata, in Object Model representation, to convert.</param> /// <param name="linkPayloadElement">The link payload element to annotate.</param> /// <remarks>This method is only for use with payload elements that represent links, as it will skip over the root link annotation.</remarks> private static void ConvertAtomLinkChildrenMetadata(AtomLinkMetadata linkMetadata, ODataPayloadElement linkPayloadElement) { ExceptionUtilities.CheckArgumentNotNull(linkMetadata, "linkMetadata"); ExceptionUtilities.CheckArgumentNotNull(linkPayloadElement, "linkPayloadElement"); // Since the payload element already represents a link, we annotate a temporary element // and copy the "children" annotations onto the actual payload element. var tempPayloadElement = new EntityInstance(); ExceptionUtilities.Assert(!tempPayloadElement.Annotations.OfType <XmlTreeAnnotation>().Any(), "Payload element should not have XmlTreeAnnotations after construction"); ConvertAtomLinkMetadata(linkMetadata, tempPayloadElement); XmlTreeAnnotation linkAnnotation = tempPayloadElement.Annotations.OfType <XmlTreeAnnotation>().Single(); foreach (XmlTreeAnnotation childAnnotation in linkAnnotation.Children) { linkPayloadElement.AddAnnotation(childAnnotation); } }
/// <summary> /// Converts the Object Model representation of Atom link metadata into appropriate annotations for a payload element representing a link. /// </summary> /// <param name="linkMetadata">The Atom link metadata, in Object Model representation, to convert.</param> /// <param name="linkPayloadElement">The link payload element to annotate.</param> /// <remarks>This method is only for use with payload elements that represent links, as it will skip over the root link annotation.</remarks> private static void ConvertAtomLinkChildrenMetadata(AtomLinkMetadata linkMetadata, ODataPayloadElement linkPayloadElement) { ExceptionUtilities.CheckArgumentNotNull(linkMetadata, "linkMetadata"); ExceptionUtilities.CheckArgumentNotNull(linkPayloadElement, "linkPayloadElement"); // Since the payload element already represents a link, we annotate a temporary element // and copy the "children" annotations onto the actual payload element. var tempPayloadElement = new EntityInstance(); ExceptionUtilities.Assert(!tempPayloadElement.Annotations.OfType<XmlTreeAnnotation>().Any(), "Payload element should not have XmlTreeAnnotations after construction"); ConvertAtomLinkMetadata(linkMetadata, tempPayloadElement); XmlTreeAnnotation linkAnnotation = tempPayloadElement.Annotations.OfType<XmlTreeAnnotation>().Single(); foreach (XmlTreeAnnotation childAnnotation in linkAnnotation.Children) { linkPayloadElement.AddAnnotation(childAnnotation); } }