@@ -52,56 +52,58 @@ public override void Initialize(AnalysisContext context)
52
52
}
53
53
}
54
54
55
- if ( properties . Count > 0 )
55
+ if ( properties . Count == 0 )
56
56
{
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 > ( ) ;
60
63
61
64
// Per-property validations
62
65
foreach ( var property in properties )
66
+ {
67
+ if ( property . SetMethod ? . DeclaredAccessibility == Accessibility . Public )
63
68
{
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
+ }
71
74
72
- if ( ComponentFacts . IsParameterWithCaptureUnmatchedValues ( symbols , property ) )
73
- {
74
- captureUnmatchedValuesParameters . Add ( property ) ;
75
+ if ( ComponentFacts . IsParameterWithCaptureUnmatchedValues ( symbols , property ) )
76
+ {
77
+ captureUnmatchedValuesParameters . Add ( property ) ;
75
78
76
79
// Check the type, we need to be able to assign a Dictionary<string, object>
77
80
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 ) ) ) ;
87
89
}
88
90
}
91
+ }
89
92
90
93
// Check if the type defines multiple CaptureUnmatchedValues parameters. Doing this outside the loop means we place the
91
94
// errors on the type.
92
95
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 (
98
103
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
+ } ) ;
105
107
} , SymbolKind . NamedType ) ;
106
108
} ) ;
107
109
}
0 commit comments