File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed
Microsoft.Toolkit.Uwp.UI.Media/Extensions/System Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change 4
4
5
5
using System ;
6
6
using System . Diagnostics . Contracts ;
7
- using System . Linq ;
8
7
9
8
namespace Microsoft . Toolkit . Uwp . UI . Media
10
9
{
@@ -19,12 +18,19 @@ internal static class GuidExtensions
19
18
/// <param name="guid">The input <see cref="Guid"/> to process</param>
20
19
/// <returns>A <see cref="string"/> representation of <paramref name="guid"/> only made up of letters in the [A-Z] range</returns>
21
20
[ Pure ]
22
- public static string ToUppercaseAsciiLetters ( this Guid guid )
21
+ public static string ToUppercaseAsciiLetters ( in this Guid guid )
23
22
{
24
- return new string ( (
25
- from c in guid . ToString ( "N" )
26
- let l = char . IsDigit ( c ) ? ( char ) ( 'G' + c - '0' ) : c
27
- select l ) . ToArray ( ) ) ;
23
+ // Composition IDs must only be composed of characters in the [A-Z0-9_] set,
24
+ // and also have the restriction that the initial character cannot be a digit.
25
+ // Because of this, we need to prepend an underscore to a serialized guid to
26
+ // avoid cases where the first character is a digit. Additionally, we're forced
27
+ // to use ToUpper() here because ToString("N") currently returns a lowercase
28
+ // hexadecimal string. Note: this extension might be improved once we move to
29
+ // .NET 5 in the WinUI 3 release, by using string.Create<TState>(...) to only
30
+ // have a single string allocation, and then using Guid.TryFormat(...) to
31
+ // serialize the guid in place over the Span<char> starting from the second
32
+ // character. For now, this implementation is fine on UWP and still fast enough.
33
+ return $ "_{ guid . ToString ( "N" ) . ToUpper ( ) } ";
28
34
}
29
35
}
30
36
}
You can’t perform that action at this time.
0 commit comments