コード例 #1
0
        private static string GetLiteralValue(object value, ODataFormat format, PayloadGeneratorSettings settings)
        {
            JsonPayloadGenerator generator;
            if (format == ODataFormat.Json)
            {
                generator = new JsonLightPayloadGenerator(settings);
            }
            else
            {
                Assert.Fail("Format not supported by UriOperationParameterGenerator.");
                return null;
            }

            var payloadBuilder = value as PayloadBuilder;
            if (payloadBuilder != null)
            {
                return generator.GenerateLiteral(payloadBuilder);
            }

            var collectionBuilder = value as CollectionPropertyPayloadBuilder;
            if (collectionBuilder != null)
            {
                return generator.GenerateLiteral(collectionBuilder);
            }

            // Use the key syntax since that will give us single quotes and other formatting that is not used for literals as property values
            return JsonPrimitiveTypesUtil.PrimitiveToKeyString(value, value.GetType());
        }
コード例 #2
0
        public static string Generate(PayloadBuilder payloadBuilder, ODataFormat format, PayloadGeneratorSettings settings = null)
        {
            if (settings == null)
            {
                settings = new PayloadGeneratorSettings();
            }

            if (payloadBuilder == null)
            {
                return(null);
            }

            PayloadGenerator payloadGenerator = null;

            if (format == ODataFormat.Json)
            {
                payloadGenerator = new JsonLightPayloadGenerator(settings);
            }
            //else if (format == ODataFormat.Atom)
            //{
            //    payloadGenerator = new AtomPayloadGenerator(settings);
            //}
            else
            {
                Assert.Fail(String.Format("Payload generation not implemented for {0}", format));
            }

            string payload;

            if (PayloadGenerator.IsEntityBindingPayload(payloadBuilder))
            {
                payload = payloadGenerator.GenerateLinkPayload(payloadBuilder);
            }
            else
            {
                payload = payloadGenerator.Generate(payloadBuilder);
            }

            return(payload);
        }
コード例 #3
0
        public static string Generate(PayloadBuilder payloadBuilder, ODataFormat format, PayloadGeneratorSettings settings = null)
        {
            if (settings == null)
            {
                settings = new PayloadGeneratorSettings();
            }

            if (payloadBuilder == null)
            {
                return null;
            }

            PayloadGenerator payloadGenerator = null;
            if (format == ODataFormat.Json)
            {
                payloadGenerator = new JsonLightPayloadGenerator(settings);
            }
            else if (format == ODataFormat.Atom)
            {
                payloadGenerator = new AtomPayloadGenerator(settings);
            }
            else
            {
                Assert.Fail(String.Format("Payload generation not implemented for {0}", format));
            }

            string payload;
            if (PayloadGenerator.IsEntityBindingPayload(payloadBuilder))
            {
                payload = payloadGenerator.GenerateLinkPayload(payloadBuilder);
            }
            else
            {
                payload = payloadGenerator.Generate(payloadBuilder);
            }

            return payload;
        }