| | 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.Xml; |
| | 8 | |
|
| | 9 | | namespace Azure.Core |
| | 10 | | { |
| | 11 | | internal static class XmlWriterExtensions |
| | 12 | | { |
| | 13 | | public static void WriteObjectValue(this XmlWriter writer, object value, string? nameHint) |
| | 14 | | { |
| | 15 | | switch (value) |
| | 16 | | { |
| | 17 | | case IXmlSerializable serializable: |
| 0 | 18 | | serializable.Write(writer, nameHint); |
| 0 | 19 | | return; |
| | 20 | | default: |
| 0 | 21 | | throw new NotImplementedException(); |
| | 22 | | } |
| | 23 | | } |
| | 24 | |
|
| | 25 | | public static void WriteValue(this XmlWriter writer, DateTimeOffset value, string format) => |
| 0 | 26 | | writer.WriteValue(TypeFormatters.ToString(value, format)); |
| | 27 | |
|
| | 28 | | public static void WriteValue(this XmlWriter writer, TimeSpan value, string format) => |
| 0 | 29 | | writer.WriteValue(TypeFormatters.ToString(value, format)); |
| | 30 | |
|
| | 31 | | public static void WriteValue(this XmlWriter writer, byte[] value, string format) |
| | 32 | | { |
| | 33 | | switch (format) |
| | 34 | | { |
| | 35 | | case "U": |
| 0 | 36 | | writer.WriteValue(TypeFormatters.ToBase64UrlString(value)); |
| 0 | 37 | | break; |
| | 38 | | default: |
| 0 | 39 | | throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)); |
| | 40 | | } |
| | 41 | | } |
| | 42 | | } |
| | 43 | | } |