| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | #nullable enable |
| | 5 | |
|
| | 6 | | using System; |
| | 7 | | using System.Collections.Generic; |
| | 8 | | using System.Globalization; |
| | 9 | | using System.Xml; |
| | 10 | |
|
| | 11 | | namespace Azure.Core |
| | 12 | | { |
| | 13 | | internal static class RequestUriBuilderExtensions |
| | 14 | | { |
| | 15 | | public static void AppendPath(this RequestUriBuilder builder, bool value, bool escape = false) |
| | 16 | | { |
| 0 | 17 | | builder.AppendPath(TypeFormatters.ToString(value), escape); |
| 0 | 18 | | } |
| | 19 | |
|
| | 20 | | public static void AppendPath(this RequestUriBuilder builder, float value, bool escape = true) |
| | 21 | | { |
| 0 | 22 | | builder.AppendPath(value.ToString(TypeFormatters.DefaultNumberFormat, CultureInfo.InvariantCulture), escape) |
| 0 | 23 | | } |
| | 24 | |
|
| | 25 | | public static void AppendPath(this RequestUriBuilder builder, double value, bool escape = true) |
| | 26 | | { |
| 0 | 27 | | builder.AppendPath(value.ToString(TypeFormatters.DefaultNumberFormat, CultureInfo.InvariantCulture), escape) |
| 0 | 28 | | } |
| | 29 | |
|
| | 30 | | public static void AppendPath(this RequestUriBuilder builder, int value, bool escape = true) |
| | 31 | | { |
| 160 | 32 | | builder.AppendPath(value.ToString(TypeFormatters.DefaultNumberFormat, CultureInfo.InvariantCulture), escape) |
| 160 | 33 | | } |
| | 34 | |
|
| | 35 | | public static void AppendPath(this RequestUriBuilder builder, byte[] value, bool escape = true) |
| | 36 | | { |
| 0 | 37 | | builder.AppendPath(TypeFormatters.ToBase64UrlString(value), escape); |
| 0 | 38 | | } |
| | 39 | |
|
| | 40 | | public static void AppendPath(this RequestUriBuilder builder, IEnumerable<string> value, bool escape = true) |
| | 41 | | { |
| 0 | 42 | | builder.AppendPath(string.Join(",", value), escape); |
| 0 | 43 | | } |
| | 44 | |
|
| | 45 | | public static void AppendPath(this RequestUriBuilder builder, DateTimeOffset value, string format, bool escape = |
| | 46 | | { |
| 0 | 47 | | builder.AppendPath(TypeFormatters.ToString(value, format), escape); |
| 0 | 48 | | } |
| | 49 | |
|
| | 50 | | public static void AppendPath(this RequestUriBuilder builder, TimeSpan value, string format, bool escape = true) |
| | 51 | | { |
| 0 | 52 | | builder.AppendPath(TypeFormatters.ToString(value, format), escape); |
| 0 | 53 | | } |
| | 54 | |
|
| | 55 | | public static void AppendPath(this RequestUriBuilder builder, Guid value, bool escape = true) |
| | 56 | | { |
| 0 | 57 | | builder.AppendPath(value.ToString(), escape); |
| 0 | 58 | | } |
| | 59 | |
|
| | 60 | | public static void AppendQuery(this RequestUriBuilder builder, string name, bool value, bool escape = false) |
| | 61 | | { |
| 0 | 62 | | builder.AppendQuery(name, TypeFormatters.ToString(value), escape); |
| 0 | 63 | | } |
| | 64 | |
|
| | 65 | | public static void AppendQuery(this RequestUriBuilder builder, string name, float value, bool escape = true) |
| | 66 | | { |
| 0 | 67 | | builder.AppendQuery(name, value.ToString(TypeFormatters.DefaultNumberFormat, CultureInfo.InvariantCulture), |
| 0 | 68 | | } |
| | 69 | |
|
| | 70 | | public static void AppendQuery(this RequestUriBuilder builder, string name, DateTimeOffset value, string format, |
| | 71 | | { |
| 0 | 72 | | builder.AppendQuery(name, TypeFormatters.ToString(value, format), escape); |
| 0 | 73 | | } |
| | 74 | |
|
| | 75 | | public static void AppendQuery(this RequestUriBuilder builder, string name, TimeSpan value, string format, bool |
| | 76 | | { |
| 0 | 77 | | builder.AppendQuery(name, TypeFormatters.ToString(value, format), escape); |
| 0 | 78 | | } |
| | 79 | |
|
| | 80 | | public static void AppendQuery(this RequestUriBuilder builder, string name, double value, bool escape = true) |
| | 81 | | { |
| 0 | 82 | | builder.AppendQuery(name, value.ToString(TypeFormatters.DefaultNumberFormat, CultureInfo.InvariantCulture), |
| 0 | 83 | | } |
| | 84 | |
|
| | 85 | | public static void AppendQuery(this RequestUriBuilder builder, string name, int value, bool escape = true) |
| | 86 | | { |
| 0 | 87 | | builder.AppendQuery(name, value.ToString(TypeFormatters.DefaultNumberFormat, CultureInfo.InvariantCulture), |
| 0 | 88 | | } |
| | 89 | |
|
| | 90 | | public static void AppendQuery(this RequestUriBuilder builder, string name, TimeSpan value, bool escape = true) |
| | 91 | | { |
| 0 | 92 | | builder.AppendQuery(name, XmlConvert.ToString(value), escape); |
| 0 | 93 | | } |
| | 94 | |
|
| | 95 | | public static void AppendQuery(this RequestUriBuilder builder, string name, byte[] value, bool escape = true) |
| | 96 | | { |
| 0 | 97 | | builder.AppendQuery(name, Convert.ToBase64String(value), escape); |
| 0 | 98 | | } |
| | 99 | |
|
| | 100 | | public static void AppendQuery(this RequestUriBuilder builder, string name, Guid value, bool escape = true) |
| | 101 | | { |
| 0 | 102 | | builder.AppendQuery(name, value.ToString(), escape); |
| 0 | 103 | | } |
| | 104 | |
|
| | 105 | | public static void AppendQueryDelimited<T>(this RequestUriBuilder builder, string name, IEnumerable<T> value, st |
| | 106 | | { |
| 0 | 107 | | builder.AppendQuery(name, string.Join(delimiter, value), escape); |
| 0 | 108 | | } |
| | 109 | | } |
| | 110 | | } |