示例#1
0
        /// <summary>
        /// Gets the expected payload type for a request to the given uri
        /// </summary>
        /// <param name="requestUri">The request uri</param>
        /// <returns>The expected payload type</returns>
        public static ODataPayloadElementType GetExpectedPayloadType(this ODataUri requestUri)
        {
            if (requestUri.Segments.OfType <UnrecognizedSegment>().Any())
            {
                return(ODataPayloadElementType.Unknown);
            }

            if (requestUri.IsMetadata())
            {
                return(ODataPayloadElementType.MetadataPayloadElement);
            }

            if (requestUri.IsBatch())
            {
                return(ODataPayloadElementType.BatchResponsePayload);
            }

            if (requestUri.IsCount() || requestUri.IsPropertyValue() || requestUri.IsMediaResource() || requestUri.IsNamedStream())
            {
                return(ODataPayloadElementType.PrimitiveValue);
            }

            if (requestUri.IsEntity())
            {
                return(ODataPayloadElementType.EntityInstance);
            }

            if (requestUri.IsEntitySet())
            {
                return(ODataPayloadElementType.EntitySetInstance);
            }

            if (requestUri.IsEntityReferenceLink())
            {
                return(requestUri.GetExpectedLinkPayloadType());
            }

            if (requestUri.IsProperty())
            {
                var property = requestUri.Segments.OfType <PropertySegment>().Last();
                return(property.Property.GetExpectedPayloadType());
            }

            if (requestUri.IsServiceOperation() || requestUri.IsAction())
            {
                var serviceOp = requestUri.Segments.OfType <FunctionSegment>().Last();
                return(serviceOp.Function.GetExpectedPayloadType());
            }

            return(ODataPayloadElementType.Unknown);
        }