Open vladd opened 8 hours ago
Offtopic: I'm using ToDisplayString for determining type's escaped name in code generation. Is there a better way?
Use SyntaxFacts to ask if it's a keyword
@CyrusNajmabadi Thank you, this fixes my problem. Nevertheless, the inconsistency of ToDisplayName is still there and should be corrected.
@CyrusNajmabadi Well, my problem is not fixed completely, as ToDisplayName handles generic arguments as well.
The problem is here: https://github.com/dotnet/roslyn/blob/bbd787e1eb55b176f3274b84bd48ada0b210c846/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.cs#L114
private static bool IsEscapable(SymbolDisplayPartKind kind)
{
switch (kind)
{
case SymbolDisplayPartKind.AliasName:
case SymbolDisplayPartKind.ClassName:
case SymbolDisplayPartKind.RecordClassName:
case SymbolDisplayPartKind.StructName:
case SymbolDisplayPartKind.RecordStructName:
case SymbolDisplayPartKind.InterfaceName:
case SymbolDisplayPartKind.EnumName:
case SymbolDisplayPartKind.DelegateName:
case SymbolDisplayPartKind.TypeParameterName:
case SymbolDisplayPartKind.MethodName:
case SymbolDisplayPartKind.PropertyName:
case SymbolDisplayPartKind.FieldName:
case SymbolDisplayPartKind.LocalName:
case SymbolDisplayPartKind.NamespaceName:
case SymbolDisplayPartKind.ParameterName:
return true;
default:
return false;
}
}
It must have included SymbolDisplayPartKind.RecordStructName
too.
Version Used:
Microsoft.CodeAnalysis.CSharp version 4.11.0
Steps to Reproduce:
INamedTypeSymbol
for a record struct namedvoid
ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat)
@
-symbol in display stringRepro:
Project file:
Expected Behavior:
Display string should be consistent for all kinds of symbols, especially for structs and record structs.
Test code above outputs
Actual Behavior:
Record struct's display string doesn't escape identifiers.
Test code outputs