@@ -56,7 +56,7 @@ public void Execute(GeneratorExecutionContext context)
5656 /// <param name="classDeclaration">The <see cref="ClassDeclarationSyntax"/> node to process.</param>
5757 /// <param name="classDeclarationSymbol">The <see cref="INamedTypeSymbol"/> for <paramref name="classDeclaration"/>.</param>
5858 /// <param name="items">The sequence of fields to process.</param>
59- private static void OnExecute (
59+ private void OnExecute (
6060 GeneratorExecutionContext context ,
6161 ClassDeclarationSyntax classDeclaration ,
6262 INamedTypeSymbol classDeclarationSymbol ,
@@ -71,7 +71,7 @@ private static void OnExecute(
7171 var classDeclarationSyntax =
7272 ClassDeclaration ( classDeclarationSymbol . Name )
7373 . WithModifiers ( classDeclaration . Modifiers )
74- . AddMembers ( items . Select ( static item => CreatePropertyDeclaration ( item . LeadingTrivia , item . FieldSymbol ) ) . ToArray ( ) ) ;
74+ . AddMembers ( items . Select ( item => CreatePropertyDeclaration ( item . LeadingTrivia , item . FieldSymbol ) ) . ToArray ( ) ) ;
7575
7676 TypeDeclarationSyntax typeDeclarationSyntax = classDeclarationSyntax ;
7777
@@ -92,15 +92,12 @@ private static void OnExecute(
9292
9393 // Create the final compilation unit to generate (with leading trivia)
9494 var source =
95- CompilationUnit ( ) . AddUsings (
96- UsingDirective ( IdentifierName ( "System.Collections.Generic" ) ) . WithLeadingTrivia ( TriviaList (
97- Comment ( "// Licensed to the .NET Foundation under one or more agreements." ) ,
98- Comment ( "// The .NET Foundation licenses this file to you under the MIT license." ) ,
99- Comment ( "// See the LICENSE file in the project root for more information." ) ,
100- Trivia ( PragmaWarningDirectiveTrivia ( Token ( SyntaxKind . DisableKeyword ) , true ) ) ) ) ,
101- UsingDirective ( IdentifierName ( "System.Diagnostics" ) ) ,
102- UsingDirective ( IdentifierName ( "System.Diagnostics.CodeAnalysis" ) ) ) . AddMembers (
103- NamespaceDeclaration ( IdentifierName ( namespaceName ) )
95+ CompilationUnit ( ) . AddMembers (
96+ NamespaceDeclaration ( IdentifierName ( namespaceName ) ) . WithLeadingTrivia ( TriviaList (
97+ Comment ( "// Licensed to the .NET Foundation under one or more agreements." ) ,
98+ Comment ( "// The .NET Foundation licenses this file to you under the MIT license." ) ,
99+ Comment ( "// See the LICENSE file in the project root for more information." ) ,
100+ Trivia ( PragmaWarningDirectiveTrivia ( Token ( SyntaxKind . DisableKeyword ) , true ) ) ) )
104101 . AddMembers ( typeDeclarationSyntax ) )
105102 . NormalizeWhitespace ( )
106103 . ToFullString ( ) ;
@@ -116,7 +113,7 @@ private static void OnExecute(
116113 /// <param name="fieldSymbol">The input <see cref="IFieldSymbol"/> instance to process.</param>
117114 /// <returns>A generated <see cref="PropertyDeclarationSyntax"/> instance for the input field.</returns>
118115 [ Pure ]
119- private static PropertyDeclarationSyntax CreatePropertyDeclaration ( SyntaxTriviaList leadingTrivia , IFieldSymbol fieldSymbol )
116+ private PropertyDeclarationSyntax CreatePropertyDeclaration ( SyntaxTriviaList leadingTrivia , IFieldSymbol fieldSymbol )
120117 {
121118 // Get the field type and the target property name
122119 string
@@ -154,14 +151,15 @@ private static PropertyDeclarationSyntax CreatePropertyDeclaration(SyntaxTriviaL
154151 // Construct the generated property as follows:
155152 //
156153 // <FIELD_TRIVIA>
157- // [DebuggerNonUserCode]
158- // [ExcludeFromCodeCoverage]
154+ // [global::System.CodeDom.Compiler.GeneratedCode("...", "...")]
155+ // [global::System.Diagnostics.DebuggerNonUserCode]
156+ // [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
159157 // public <FIELD_TYPE> <PROPERTY_NAME>
160158 // {
161159 // get => <FIELD_NAME>;
162160 // set
163161 // {
164- // if (!EqualityComparer<<FIELD_TYPE>>.Default.Equals(<FIELD_NAME>, value))
162+ // if (!global::System.Collections.Generic. EqualityComparer<<FIELD_TYPE>>.Default.Equals(<FIELD_NAME>, value))
165163 // {
166164 // OnPropertyChanging(); // Optional
167165 // <FIELD_NAME> = value;
@@ -172,8 +170,13 @@ private static PropertyDeclarationSyntax CreatePropertyDeclaration(SyntaxTriviaL
172170 return
173171 PropertyDeclaration ( IdentifierName ( typeName ) , Identifier ( propertyName ) )
174172 . AddAttributeLists (
175- AttributeList ( SingletonSeparatedList ( Attribute ( IdentifierName ( "DebuggerNonUserCode" ) ) ) ) ,
176- AttributeList ( SingletonSeparatedList ( Attribute ( IdentifierName ( "ExcludeFromCodeCoverage" ) ) ) ) )
173+ AttributeList ( SingletonSeparatedList (
174+ Attribute ( IdentifierName ( $ "global::System.CodeDom.Compiler.GeneratedCode") )
175+ . AddArgumentListArguments (
176+ AttributeArgument ( LiteralExpression ( SyntaxKind . StringLiteralExpression , Literal ( GetType ( ) . FullName ) ) ) ,
177+ AttributeArgument ( LiteralExpression ( SyntaxKind . StringLiteralExpression , Literal ( GetType ( ) . Assembly . GetName ( ) . Version . ToString ( ) ) ) ) ) ) ) ,
178+ AttributeList ( SingletonSeparatedList ( Attribute ( IdentifierName ( "global::System.Diagnostics.DebuggerNonUserCode" ) ) ) ) ,
179+ AttributeList ( SingletonSeparatedList ( Attribute ( IdentifierName ( "global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage" ) ) ) ) )
177180 . WithLeadingTrivia ( leadingTrivia )
178181 . AddModifiers ( Token ( SyntaxKind . PublicKeyword ) )
179182 . AddAccessorListAccessors (
@@ -190,7 +193,7 @@ private static PropertyDeclarationSyntax CreatePropertyDeclaration(SyntaxTriviaL
190193 SyntaxKind . SimpleMemberAccessExpression ,
191194 MemberAccessExpression (
192195 SyntaxKind . SimpleMemberAccessExpression ,
193- GenericName ( Identifier ( "EqualityComparer" ) )
196+ GenericName ( Identifier ( "global::System.Collections.Generic. EqualityComparer" ) )
194197 . AddTypeArgumentListArguments ( IdentifierName ( typeName ) ) ,
195198 IdentifierName ( "Default" ) ) ,
196199 IdentifierName ( "Equals" ) ) )
0 commit comments