-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathStringExtensions.cs
More file actions
50 lines (43 loc) · 1.34 KB
/
StringExtensions.cs
File metadata and controls
50 lines (43 loc) · 1.34 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
using System;
using System.Net.Mime;
namespace Microsoft.Extensions.Configuration.AzureAppConfiguration.Extensions
{
internal static class StringExtensions
{
public static bool TryParseContentType(this string contentTypeString, out ContentType? contentType)
{
contentType = null;
if (string.IsNullOrWhiteSpace(contentTypeString))
{
return false;
}
try
{
contentType = new ContentType(contentTypeString.Trim());
return true;
}
catch (FormatException)
{
return false;
}
catch (IndexOutOfRangeException)
{
// Bug in System.Net.Mime.ContentType throws this if contentType is "xyz/"
// https://github.com/dotnet/runtime/issues/39337
return false;
}
}
public static string? NormalizeNull(this string? s)
{
return s == LabelFilter.Null ? null : s;
}
public static string ToBase64String(this string s)
{
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(s);
return Convert.ToBase64String(bytes);
}
}
}