-
Notifications
You must be signed in to change notification settings - Fork 176
Expand file tree
/
Copy pathXElementExtensions.cs
More file actions
34 lines (29 loc) · 1.29 KB
/
XElementExtensions.cs
File metadata and controls
34 lines (29 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#nullable enable
using System;
using System.Xml.Linq;
namespace Azure.Core
{
internal static class XElementExtensions
{
public static byte[] GetBytesFromBase64Value(this XElement element, string format) => format switch
{
"U" => TypeFormatters.FromBase64UrlString(element.Value),
"D" => Convert.FromBase64String(element.Value),
_ => throw new ArgumentException($"Format is not supported: '{format}'", nameof(format))
};
public static DateTimeOffset GetDateTimeOffsetValue(this XElement element, string format) => format switch
{
"U" => DateTimeOffset.FromUnixTimeSeconds((long)element),
_ => TypeFormatters.ParseDateTimeOffset(element.Value, format)
};
public static TimeSpan GetTimeSpanValue(this XElement element, string format) => TypeFormatters.ParseTimeSpan(element.Value, format);
#pragma warning disable CA1801 //Parameter format of method GetObjectValue is never used. Remove the parameter or use it in the method body.
public static object GetObjectValue(this XElement element, string format)
#pragma warning restore
{
return element.Value;
}
}
}