/// <summary> /// Annotates payload with version as appropriate. /// </summary> /// <param name="payloadElement">The root of the payload to annotate.</param> /// <param name="version">The format version to annotate with.</param> /// <param name="requestPayload">true if the payload should represent a request payload, false if it's a response payload.</param> public static void AnnotateVerboseJson(ODataPayloadElement payloadElement, DataServiceProtocolVersion version, bool requestPayload) { PayloadFormatVersionAnnotatingVisitor visitor = new PayloadFormatVersionAnnotatingVisitor(version, requestPayload); visitor.Recurse(payloadElement); // Add the version/response annotation to the root if it's a response. if (!requestPayload && !(payloadElement is ODataErrorPayload)) { payloadElement.SetAnnotation(new PayloadFormatVersionAnnotation() { Version = version, Response = true, ResponseWrapper = true }); } }
/// <summary> /// Gets or adds the expected type annotation. /// </summary> /// <param name="payloadElement">The payload element to get or add the annotation to.</param> /// <returns>The expected type annotation to use.</returns> public static ExpectedTypeODataPayloadElementAnnotation AddExpectedTypeAnnotation(this ODataPayloadElement payloadElement) { Debug.Assert(payloadElement != null, "payloadElement != null"); var expectedTypeAnnotation = payloadElement.GetAnnotation <ExpectedTypeODataPayloadElementAnnotation>(); if (expectedTypeAnnotation == null) { expectedTypeAnnotation = new ExpectedTypeODataPayloadElementAnnotation(); payloadElement.SetAnnotation(expectedTypeAnnotation); } return(expectedTypeAnnotation); }
/// <summary> /// Gets or adds the expected type annotation. /// </summary> /// <param name="payloadElement">The payload element to get or add the annotation to.</param> /// <returns>The expected type annotation to use.</returns> public static ExpectedTypeODataPayloadElementAnnotation AddExpectedTypeAnnotation(this ODataPayloadElement payloadElement, IEdmType expectedType) { Debug.Assert(payloadElement != null, "payloadElement != null"); var expectedTypeAnnotation = payloadElement.GetAnnotation <ExpectedTypeODataPayloadElementAnnotation>(); if (expectedTypeAnnotation == null) { expectedTypeAnnotation = new ExpectedTypeODataPayloadElementAnnotation(); payloadElement.SetAnnotation(expectedTypeAnnotation); } expectedTypeAnnotation.EdmExpectedType = expectedType.ToTypeReference(); return(expectedTypeAnnotation); }
/// <summary> /// Sets an expected type annotation. /// </summary> /// <param name="payloadElement">The payload element to set the annotation on.</param> /// <param name="annotation">The <see cref="ExpectedTypeODataPayloadElementAnnotation"/> to add to <paramref name="payloadElement"/>.</param> /// <returns>The annotated <paramref name="payloadElement"/> for composability.</returns> public static ODataPayloadElement AddExpectedTypeAnnotation(this ODataPayloadElement payloadElement, ExpectedTypeODataPayloadElementAnnotation annotation) { Debug.Assert(payloadElement != null, "payloadElement != null"); payloadElement.SetAnnotation(annotation); return(payloadElement); }