| | 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.Globalization; |
| | 8 | | using System.Xml; |
| | 9 | | using System.Xml.Linq; |
| | 10 | |
|
| | 11 | | namespace Azure.Core |
| | 12 | | { |
| | 13 | | internal static class XElementExtensions |
| | 14 | | { |
| 0 | 15 | | public static byte[] GetBytesFromBase64Value(this XElement element, string format) => format switch |
| 0 | 16 | | { |
| 0 | 17 | | "U" => TypeFormatters.FromBase64UrlString(element.Value), |
| 0 | 18 | | _ => throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)) |
| 0 | 19 | | }; |
| | 20 | |
|
| 0 | 21 | | public static DateTimeOffset GetDateTimeOffsetValue(this XElement element, string format) => format switch |
| 0 | 22 | | { |
| 0 | 23 | | "U" => DateTimeOffset.FromUnixTimeSeconds((long)element), |
| 0 | 24 | | _ => TypeFormatters.ParseDateTimeOffset(element.Value, format) |
| 0 | 25 | | }; |
| | 26 | |
|
| 0 | 27 | | public static TimeSpan GetTimeSpanValue(this XElement element, string format) => TypeFormatters.ParseTimeSpan(el |
| | 28 | | #pragma warning disable CA1801 //Parameter format of method GetObjectValue is never used. Remove the parameter o |
| | 29 | | public static object GetObjectValue(this XElement element, string format) |
| | 30 | | #pragma warning restore |
| | 31 | | { |
| 0 | 32 | | return element.Value; |
| | 33 | | } |
| | 34 | | } |
| | 35 | | } |