Skip to content

Commit babbfb0

Browse files
Merge pull request #61875 from dotnet/jamesnk/virtualchar-rune
Fix Rune access issue on AspNetCoreVirtualChar
2 parents 06f579b + 8427645 commit babbfb0

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/Tools/ExternalAccess/AspNetCore/EmbeddedLanguages/AspNetCoreVirtualChar.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System;
56
using System.Text;
67
using Microsoft.CodeAnalysis.EmbeddedLanguages.VirtualChars;
78
using Microsoft.CodeAnalysis.Text;
89

910
namespace Microsoft.CodeAnalysis.ExternalAccess.AspNetCore.EmbeddedLanguages
1011
{
11-
internal readonly struct AspNetCoreVirtualChar
12+
internal readonly struct AspNetCoreVirtualChar : IEquatable<AspNetCoreVirtualChar>
1213
{
1314
private readonly VirtualChar _virtualChar;
1415

@@ -17,8 +18,15 @@ internal AspNetCoreVirtualChar(VirtualChar virtualChar)
1718
_virtualChar = virtualChar;
1819
}
1920

20-
/// <inheritdoc cref="VirtualChar.Rune"/>
21-
public Rune Rune => _virtualChar.Rune;
21+
/// <summary>
22+
/// Returns the Unicode scalar value as an integer.
23+
/// </summary>
24+
public int RuneValue
25+
{
26+
// Rune is an internal shim with netstandard2.0 and accessing it throws an internal access exception.
27+
// Expose integer value. Can be converted back to Rune by caller.
28+
get => _virtualChar.Rune.Value;
29+
}
2230

2331
/// <inheritdoc cref="VirtualChar.SurrogateChar"/>
2432
public char SurrogateChar => _virtualChar.SurrogateChar;
@@ -31,5 +39,14 @@ internal AspNetCoreVirtualChar(VirtualChar virtualChar)
3139

3240
/// <inheritdoc cref="VirtualChar.ToString"/>
3341
public override string ToString() => _virtualChar.ToString();
42+
43+
/// <inheritdoc cref="VirtualChar.Equals(object)"/>
44+
public override bool Equals(object? obj) => obj is AspNetCoreVirtualChar vc && Equals(vc);
45+
46+
/// <inheritdoc cref="VirtualChar.Equals(VirtualChar)"/>
47+
public bool Equals(AspNetCoreVirtualChar other) => _virtualChar.Equals(other._virtualChar);
48+
49+
/// <inheritdoc cref="VirtualChar.GetHashCode"/>
50+
public override int GetHashCode() => _virtualChar.GetHashCode();
3451
}
3552
}

0 commit comments

Comments
 (0)