@@ -10,6 +10,12 @@ public class AttributeWriter(Compilation compilation)
1010{
1111 private const string TUnitRootNamespace = "TUnit" ;
1212
13+ // Attribute constructors are C# expressions; reflection names must retain raw identifiers.
14+ private static readonly SymbolDisplayFormat AttributeTypeFormat =
15+ DisplayFormats . FullyQualifiedGenericWithGlobalPrefix . WithMiscellaneousOptions (
16+ DisplayFormats . FullyQualifiedGenericWithGlobalPrefix . MiscellaneousOptions |
17+ SymbolDisplayMiscellaneousOptions . EscapeKeywordIdentifiers ) ;
18+
1319 private readonly Dictionary < AttributeData , string > _attributeObjectInitializerCache = new ( ) ;
1420 private readonly Dictionary < INamedTypeSymbol , string > _argumentFreeAttributeInitializerCache = new ( SymbolEqualityComparer . Default ) ;
1521 private readonly Dictionary < INamedTypeSymbol , bool > _tunitRelatedCache = new ( SymbolEqualityComparer . Default ) ;
@@ -134,7 +140,7 @@ private string GetAttributeObjectInitializerInner(AttributeData attributeData, A
134140
135141 var constructorArgs = arguments . Where ( x => x . NameEquals == null ) ;
136142
137- var attributeName = attributeData . AttributeClass ! . GloballyQualified ( ) ;
143+ var attributeName = attributeData . AttributeClass ! . ToDisplayString ( AttributeTypeFormat ) ;
138144
139145 var formattedConstructorArgs = string . Join ( ", " , constructorArgs . Select ( x => FormatConstructorArgument ( x ) ) ) ;
140146
@@ -178,7 +184,7 @@ private string FormatProperty(AttributeArgumentSyntax attributeArgumentSyntax)
178184
179185 public static void WriteAttributeWithoutSyntax ( ICodeWriter sourceCodeWriter , AttributeData attributeData )
180186 {
181- var attributeName = attributeData . AttributeClass ! . GloballyQualified ( ) ;
187+ var attributeName = attributeData . AttributeClass ! . ToDisplayString ( AttributeTypeFormat ) ;
182188
183189 // Skip if any constructor arguments contain compiler-generated types
184190 if ( attributeData . ConstructorArguments . Any ( arg =>
0 commit comments