|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | 3 | // See the LICENSE file in the project root for more information. |
4 | 4 |
|
| 5 | +using System; |
5 | 6 | using System.Diagnostics.CodeAnalysis; |
6 | 7 | using System.Globalization; |
7 | 8 | using System.Net; |
@@ -38,17 +39,17 @@ public static class StringExtensions |
38 | 39 | /// <summary> |
39 | 40 | /// Regular expression for removing comments from HTML. |
40 | 41 | /// </summary> |
41 | | - private static readonly Regex RemoveHtmlCommentsRegex = new Regex("<!--.*?-->", RegexOptions.Singleline); |
| 42 | + private static readonly Regex RemoveHtmlCommentsRegex = new("<!--.*?-->", RegexOptions.Singleline); |
42 | 43 |
|
43 | 44 | /// <summary> |
44 | 45 | /// Regular expression for removing scripts from HTML. |
45 | 46 | /// </summary> |
46 | | - private static readonly Regex RemoveHtmlScriptsRegex = new Regex(@"(?s)<script.*?(/>|</script>)", RegexOptions.Singleline | RegexOptions.IgnoreCase); |
| 47 | + private static readonly Regex RemoveHtmlScriptsRegex = new(@"(?s)<script.*?(/>|</script>)", RegexOptions.Singleline | RegexOptions.IgnoreCase); |
47 | 48 |
|
48 | 49 | /// <summary> |
49 | 50 | /// Regular expression for removing styles from HTML. |
50 | 51 | /// </summary> |
51 | | - private static readonly Regex RemoveHtmlStylesRegex = new Regex(@"(?s)<style.*?(/>|</style>)", RegexOptions.Singleline | RegexOptions.IgnoreCase); |
| 52 | + private static readonly Regex RemoveHtmlStylesRegex = new(@"(?s)<style.*?(/>|</style>)", RegexOptions.Singleline | RegexOptions.IgnoreCase); |
52 | 53 |
|
53 | 54 | /// <summary> |
54 | 55 | /// Determines whether a string is a valid email address. |
@@ -145,7 +146,17 @@ public static string FixHtml(this string html) |
145 | 146 | /// <param name="format">The format of the string being linked.</param> |
146 | 147 | /// <param name="args">The object which will receive the linked String.</param> |
147 | 148 | /// <returns>Truncated string.</returns> |
148 | | - public static string AsFormat(this string format, params object[] args) => string.Format(format, args); |
| 149 | + [Obsolete("This method will be removed in a future version of the Toolkit. Use the native C# string interpolation syntax instead, see: https://docs.microsoft.com/dotnet/csharp/language-reference/tokens/interpolated")] |
| 150 | + public static string AsFormat(this string format, params object[] args) |
| 151 | + { |
| 152 | + // Note: this extension was originally added to help developers using {x:Bind} in XAML, but |
| 153 | + // due to a known limitation in the UWP/WinUI XAML compiler, using either this method or the |
| 154 | + // standard string.Format method from the BCL directly doesn't always work. Since this method |
| 155 | + // doesn't actually provide any benefit over the built-in one, it has been marked as obsolete. |
| 156 | + // For more details, see the WinUI issue on the XAML compiler limitation here: |
| 157 | + // https://github.com/microsoft/microsoft-ui-xaml/issues/2654. |
| 158 | + return string.Format(format, args); |
| 159 | + } |
149 | 160 |
|
150 | 161 | /// <summary> |
151 | 162 | /// Truncates a string to the specified length. |
|
0 commit comments