@@ -58,10 +58,8 @@ private static void AnalyzeFieldDeclaration(SyntaxNodeAnalysisContext context)
58
58
{
59
59
foreach ( var classMember in classSymbol . GetMembers ( ) )
60
60
{
61
- if ( classMember . Kind == SymbolKind . Property )
61
+ if ( classMember . Kind == SymbolKind . Property && classMember is IPropertySymbol classProperty )
62
62
{
63
- var classProperty = classMember as IPropertySymbol ;
64
-
65
63
if ( ! classProperty . IsIndexer )
66
64
{
67
65
if ( DetermineIfPropertyUsesField ( context , fieldSymbol , classProperty ) )
@@ -93,9 +91,7 @@ private static void CheckForDiagnostics(SyntaxNodeAnalysisContext context, Field
93
91
}
94
92
}
95
93
96
- private static bool DetermineIfPropertyUsesField ( SyntaxNodeAnalysisContext context ,
97
- IFieldSymbol fieldSymbol , IPropertySymbol classProperty ,
98
- Func < PropertyDeclarationSyntax , SyntaxNode > propertyBody )
94
+ private static bool DetermineIfPropertyUsesField ( SyntaxNodeAnalysisContext context , IFieldSymbol fieldSymbol , IPropertySymbol classProperty , Func < PropertyDeclarationSyntax , SyntaxNode ? > propertyBody )
99
95
{
100
96
var root = context . Node . SyntaxTree . GetRoot ( ) ;
101
97
var rootSpan = root . FullSpan ;
@@ -117,23 +113,22 @@ private static bool DetermineIfPropertyUsesField(SyntaxNodeAnalysisContext conte
117
113
return false ;
118
114
}
119
115
120
- private static bool DetermineIfPropertyUsesField ( SyntaxNodeAnalysisContext context ,
121
- IFieldSymbol fieldSymbol , IPropertySymbol classProperty )
116
+ private static bool DetermineIfPropertyUsesField ( SyntaxNodeAnalysisContext context , IFieldSymbol fieldSymbol , IPropertySymbol classProperty )
122
117
{
123
118
if ( classProperty . GetMethod != null )
124
119
{
125
120
return DetermineIfPropertyUsesField (
126
121
context , fieldSymbol , classProperty ,
127
122
propertyNode => propertyNode . ExpressionBody as SyntaxNode ??
128
- propertyNode . AccessorList . Accessors . Single (
123
+ propertyNode . AccessorList ? . Accessors . Single (
129
124
_ => _ . IsKind ( SyntaxKind . GetAccessorDeclaration ) ) ) ;
130
125
}
131
126
132
127
if ( classProperty . SetMethod != null )
133
128
{
134
129
return DetermineIfPropertyUsesField (
135
130
context , fieldSymbol , classProperty ,
136
- propertyNode => propertyNode . AccessorList . Accessors . Single (
131
+ propertyNode => propertyNode . AccessorList ? . Accessors . Single (
137
132
_ => _ . IsKind ( SyntaxKind . SetAccessorDeclaration ) ) ) ;
138
133
}
139
134
0 commit comments