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())); }
internal static string Generate(OperationUriBuilder operationUriBuilder, ODataFormat format, PayloadGeneratorSettings settings) { var uriStringBuilder = new StringBuilder(); bool first = true; foreach (var parameter in operationUriBuilder.Parameters) { if (!first) { uriStringBuilder.Append(","); } string literalValue = GetLiteralValue(parameter.Value, format, settings); if (parameter.EscapeGeneratedValue) { literalValue = Uri.EscapeDataString(literalValue); } uriStringBuilder.Append(string.Format("{0}={1}", parameter.Name, literalValue)); first = false; } return(uriStringBuilder.ToString()); }