示例#1
0
        public static TElement DeserializeAndCast <TElement>(this IHttpRequest request, IProtocolFormatStrategySelector selector) where TElement : ODataPayloadElement
        {
            ExceptionUtilities.CheckArgumentNotNull(request, "request");

            var odataRequest = request as ODataRequest;

            if (odataRequest != null)
            {
                ExceptionUtilities.CheckObjectNotNull(odataRequest.Body, "OData request body unexpectedly null");
                var rootElement = odataRequest.Body.RootElement;
                var afterCast   = rootElement as TElement;
                ExceptionUtilities.CheckObjectNotNull(afterCast, "Root element was of unexpected type '{0}'. Expected '{1}'", rootElement.ElementType, ODataPayloadElement.GetElementType <TElement>());
                return(afterCast);
            }
            else
            {
                string contentType;
                ExceptionUtilities.Assert(request.TryGetHeaderValueIgnoreHeaderCase(HttpHeaders.ContentType, out contentType), "Cannot deserialize request. 'Content-Type' header not found");

                return(DeserializeAndCast <TElement>(selector, null, contentType, request.GetRequestBody()));
            }
        }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the ODataPayloadElement class.
 /// Infers the ElementType using ODataPayloadElement.GetElementType with the current instance's type
 /// </summary>
 protected ODataPayloadElement()
 {
     this.ElementType = ODataPayloadElement.GetElementType(this.GetType());
     this.Annotations = new List <ODataPayloadElementAnnotation>();
 }