@@ -38,16 +38,25 @@ public class AutoGeneratedDtoUsageAnalyzer : BaseLinqraftAnalyzer
3838 protected override void RegisterActions ( AnalysisContext context )
3939 {
4040 // Check object creation expressions (new GeneratedDto(...))
41- context . RegisterSyntaxNodeAction ( AnalyzeObjectCreation , SyntaxKind . ObjectCreationExpression ) ;
41+ context . RegisterSyntaxNodeAction (
42+ AnalyzeObjectCreation ,
43+ SyntaxKind . ObjectCreationExpression
44+ ) ;
4245
4346 // Check parameter declarations (void Foo(GeneratedDto dto))
4447 context . RegisterSyntaxNodeAction ( AnalyzeParameter , SyntaxKind . Parameter ) ;
4548
4649 // Check variable declarations (GeneratedDto dto = ...)
47- context . RegisterSyntaxNodeAction ( AnalyzeVariableDeclaration , SyntaxKind . VariableDeclaration ) ;
50+ context . RegisterSyntaxNodeAction (
51+ AnalyzeVariableDeclaration ,
52+ SyntaxKind . VariableDeclaration
53+ ) ;
4854
4955 // Check property declarations (public GeneratedDto MyDto { get; set; })
50- context . RegisterSyntaxNodeAction ( AnalyzePropertyDeclaration , SyntaxKind . PropertyDeclaration ) ;
56+ context . RegisterSyntaxNodeAction (
57+ AnalyzePropertyDeclaration ,
58+ SyntaxKind . PropertyDeclaration
59+ ) ;
5160
5261 // Check field declarations (private GeneratedDto _myDto;)
5362 context . RegisterSyntaxNodeAction ( AnalyzeFieldDeclaration , SyntaxKind . FieldDeclaration ) ;
@@ -102,7 +111,10 @@ private void AnalyzeVariableDeclaration(SyntaxNodeAnalysisContext context)
102111 return ;
103112 }
104113
105- var typeInfo = context . SemanticModel . GetTypeInfo ( variableDeclaration . Type , context . CancellationToken ) ;
114+ var typeInfo = context . SemanticModel . GetTypeInfo (
115+ variableDeclaration . Type ,
116+ context . CancellationToken
117+ ) ;
106118 var type = typeInfo . Type ;
107119
108120 if ( type != null && HasAutoGeneratedDtoAttribute ( type ) )
@@ -115,7 +127,10 @@ private void AnalyzePropertyDeclaration(SyntaxNodeAnalysisContext context)
115127 {
116128 var propertyDeclaration = ( PropertyDeclarationSyntax ) context . Node ;
117129
118- var typeInfo = context . SemanticModel . GetTypeInfo ( propertyDeclaration . Type , context . CancellationToken ) ;
130+ var typeInfo = context . SemanticModel . GetTypeInfo (
131+ propertyDeclaration . Type ,
132+ context . CancellationToken
133+ ) ;
119134 var type = typeInfo . Type ;
120135
121136 if ( type != null && HasAutoGeneratedDtoAttribute ( type ) )
@@ -128,7 +143,10 @@ private void AnalyzeFieldDeclaration(SyntaxNodeAnalysisContext context)
128143 {
129144 var fieldDeclaration = ( FieldDeclarationSyntax ) context . Node ;
130145
131- var typeInfo = context . SemanticModel . GetTypeInfo ( fieldDeclaration . Declaration . Type , context . CancellationToken ) ;
146+ var typeInfo = context . SemanticModel . GetTypeInfo (
147+ fieldDeclaration . Declaration . Type ,
148+ context . CancellationToken
149+ ) ;
132150 var type = typeInfo . Type ;
133151
134152 if ( type != null && HasAutoGeneratedDtoAttribute ( type ) )
@@ -143,35 +161,36 @@ private void AnalyzeFieldDeclaration(SyntaxNodeAnalysisContext context)
143161 private static bool HasAutoGeneratedDtoAttribute ( ITypeSymbol type )
144162 {
145163 // Check direct attributes on the type
146- return type . GetAttributes ( ) . Any ( attr =>
147- {
148- var attrClass = attr . AttributeClass ;
149- if ( attrClass == null )
164+ return type . GetAttributes ( )
165+ . Any ( attr =>
150166 {
151- return false ;
152- }
153-
154- // Optimized check: compare Name and ContainingNamespace instead of ToDisplayString()
155- if ( attrClass . Name != "LinqraftAutoGeneratedDtoAttribute" )
156- {
157- return false ;
158- }
159-
160- var containingNamespace = attrClass . ContainingNamespace ;
161- return containingNamespace != null
162- && ! containingNamespace . IsGlobalNamespace
163- && containingNamespace . Name == "Linqraft"
164- && containingNamespace . ContainingNamespace ? . IsGlobalNamespace == true ;
165- } ) ;
167+ var attrClass = attr . AttributeClass ;
168+ if ( attrClass == null )
169+ {
170+ return false ;
171+ }
172+
173+ // Optimized check: compare Name and ContainingNamespace instead of ToDisplayString()
174+ if ( attrClass . Name != "LinqraftAutoGeneratedDtoAttribute" )
175+ {
176+ return false ;
177+ }
178+
179+ var containingNamespace = attrClass . ContainingNamespace ;
180+ return containingNamespace != null
181+ && ! containingNamespace . IsGlobalNamespace
182+ && containingNamespace . Name == "Linqraft"
183+ && containingNamespace . ContainingNamespace ? . IsGlobalNamespace == true ;
184+ } ) ;
166185 }
167186
168- private void ReportDiagnostic ( SyntaxNodeAnalysisContext context , Location location , string typeName )
187+ private void ReportDiagnostic (
188+ SyntaxNodeAnalysisContext context ,
189+ Location location ,
190+ string typeName
191+ )
169192 {
170- var diagnostic = Diagnostic . Create (
171- RuleInstance ,
172- location ,
173- typeName
174- ) ;
193+ var diagnostic = Diagnostic . Create ( RuleInstance , location , typeName ) ;
175194 context . ReportDiagnostic ( diagnostic ) ;
176195 }
177196}
0 commit comments