@@ -52,56 +52,58 @@ public override void Initialize(AnalysisContext context)
5252 }
5353 }
5454
55- if ( properties . Count > 0 )
55+ if ( properties . Count == 0 )
5656 {
57- context . RegisterSymbolEndAction ( context =>
58- {
59- var captureUnmatchedValuesParameters = new List < IPropertySymbol > ( ) ;
57+ return ;
58+ }
59+
60+ context . RegisterSymbolEndAction ( context =>
61+ {
62+ var captureUnmatchedValuesParameters = new List < IPropertySymbol > ( ) ;
6063
6164 // Per-property validations
6265 foreach ( var property in properties )
66+ {
67+ if ( property . SetMethod ? . DeclaredAccessibility == Accessibility . Public )
6368 {
64- if ( property . SetMethod ? . DeclaredAccessibility == Accessibility . Public )
65- {
66- context . ReportDiagnostic ( Diagnostic . Create (
67- DiagnosticDescriptors . ComponentParametersShouldNotBePublic ,
68- property . Locations [ 0 ] ,
69- property . ToDisplayString ( SymbolDisplayFormat . CSharpErrorMessageFormat ) ) ) ;
70- }
69+ context . ReportDiagnostic ( Diagnostic . Create (
70+ DiagnosticDescriptors . ComponentParametersShouldNotBePublic ,
71+ property . Locations [ 0 ] ,
72+ property . ToDisplayString ( SymbolDisplayFormat . CSharpErrorMessageFormat ) ) ) ;
73+ }
7174
72- if ( ComponentFacts . IsParameterWithCaptureUnmatchedValues ( symbols , property ) )
73- {
74- captureUnmatchedValuesParameters . Add ( property ) ;
75+ if ( ComponentFacts . IsParameterWithCaptureUnmatchedValues ( symbols , property ) )
76+ {
77+ captureUnmatchedValuesParameters . Add ( property ) ;
7578
7679 // Check the type, we need to be able to assign a Dictionary<string, object>
7780 var conversion = context . Compilation . ClassifyConversion ( symbols . ParameterCaptureUnmatchedValuesRuntimeType , property . Type ) ;
78- if ( ! conversion . Exists || conversion . IsExplicit )
79- {
80- context . ReportDiagnostic ( Diagnostic . Create (
81- DiagnosticDescriptors . ComponentParameterCaptureUnmatchedValuesHasWrongType ,
82- property . Locations [ 0 ] ,
83- property . ToDisplayString ( SymbolDisplayFormat . CSharpErrorMessageFormat ) ,
84- property . Type . ToDisplayString ( SymbolDisplayFormat . CSharpErrorMessageFormat ) ,
85- symbols . ParameterCaptureUnmatchedValuesRuntimeType . ToDisplayString ( SymbolDisplayFormat . CSharpErrorMessageFormat ) ) ) ;
86- }
81+ if ( ! conversion . Exists || conversion . IsExplicit )
82+ {
83+ context . ReportDiagnostic ( Diagnostic . Create (
84+ DiagnosticDescriptors . ComponentParameterCaptureUnmatchedValuesHasWrongType ,
85+ property . Locations [ 0 ] ,
86+ property . ToDisplayString ( SymbolDisplayFormat . CSharpErrorMessageFormat ) ,
87+ property . Type . ToDisplayString ( SymbolDisplayFormat . CSharpErrorMessageFormat ) ,
88+ symbols . ParameterCaptureUnmatchedValuesRuntimeType . ToDisplayString ( SymbolDisplayFormat . CSharpErrorMessageFormat ) ) ) ;
8789 }
8890 }
91+ }
8992
9093 // Check if the type defines multiple CaptureUnmatchedValues parameters. Doing this outside the loop means we place the
9194 // errors on the type.
9295 if ( captureUnmatchedValuesParameters . Count > 1 )
93- {
94- context . ReportDiagnostic ( Diagnostic . Create (
95- DiagnosticDescriptors . ComponentParameterCaptureUnmatchedValuesMustBeUnique ,
96- context . Symbol . Locations [ 0 ] ,
97- type . ToDisplayString ( SymbolDisplayFormat . CSharpErrorMessageFormat ) ,
96+ {
97+ context . ReportDiagnostic ( Diagnostic . Create (
98+ DiagnosticDescriptors . ComponentParameterCaptureUnmatchedValuesMustBeUnique ,
99+ context . Symbol . Locations [ 0 ] ,
100+ type . ToDisplayString ( SymbolDisplayFormat . CSharpErrorMessageFormat ) ,
101+ Environment . NewLine ,
102+ string . Join (
98103 Environment . NewLine ,
99- string . Join (
100- Environment . NewLine ,
101- captureUnmatchedValuesParameters . Select ( p => p . ToDisplayString ( SymbolDisplayFormat . CSharpErrorMessageFormat ) ) . OrderBy ( n => n ) ) ) ) ;
102- }
103- } ) ;
104- }
104+ captureUnmatchedValuesParameters . Select ( p => p . ToDisplayString ( SymbolDisplayFormat . CSharpErrorMessageFormat ) ) . OrderBy ( n => n ) ) ) ) ;
105+ }
106+ } ) ;
105107 } , SymbolKind . NamedType ) ;
106108 } ) ;
107109 }
0 commit comments