33
44using System . Collections . Concurrent ;
55using System . Collections . Immutable ;
6- using System . Diagnostics ;
76using Microsoft . CodeAnalysis ;
87using Microsoft . CodeAnalysis . CSharp ;
98using Microsoft . CodeAnalysis . Diagnostics ;
@@ -96,11 +95,7 @@ public override void Initialize(AnalysisContext context)
9695 string ? activityName = ExtractFunctionName ( invocationOperation , "name" , ctx ) ;
9796 if ( activityName != null )
9897 {
99- activityInvocations . Add ( new FunctionInvocation
100- {
101- Name = activityName ,
102- InvocationSyntaxNode = invocationOperation . Syntax ,
103- } ) ;
98+ activityInvocations . Add ( new FunctionInvocation ( activityName , invocationOperation . Syntax ) ) ;
10499 }
105100 }
106101
@@ -110,11 +105,7 @@ public override void Initialize(AnalysisContext context)
110105 string ? orchestratorName = ExtractFunctionName ( invocationOperation , "orchestratorName" , ctx ) ;
111106 if ( orchestratorName != null )
112107 {
113- subOrchestrationInvocations . Add ( new FunctionInvocation
114- {
115- Name = orchestratorName ,
116- InvocationSyntaxNode = invocationOperation . Syntax ,
117- } ) ;
108+ subOrchestrationInvocations . Add ( new FunctionInvocation ( orchestratorName , invocationOperation . Syntax ) ) ;
118109 }
119110 }
120111 } ,
@@ -174,8 +165,7 @@ public override void Initialize(AnalysisContext context)
174165 // Check for TaskActivity<TInput, TOutput> derived classes
175166 if ( knownSymbols . TaskActivityBase != null && taskActivityRunAsync != null )
176167 {
177- IMethodSymbol ? methodOverridingRunAsync = FindOverridingMethod ( classSymbol , taskActivityRunAsync ) ;
178- if ( methodOverridingRunAsync != null )
168+ if ( ClassOverridesMethod ( classSymbol , taskActivityRunAsync ) )
179169 {
180170 activityNames . Add ( classSymbol . Name ) ;
181171 }
@@ -269,8 +259,14 @@ public override void Initialize(AnalysisContext context)
269259 return null ;
270260 }
271261
262+ SemanticModel ? semanticModel = ctx . Operation . SemanticModel ;
263+ if ( semanticModel == null )
264+ {
265+ return null ;
266+ }
267+
272268 // extracts the constant value from the argument (e.g.: it can be a nameof, string literal or const field)
273- Optional < object ? > constant = ctx . Operation . SemanticModel ! . GetConstantValue ( nameArgumentOperation . Value . Syntax ) ;
269+ Optional < object ? > constant = semanticModel . GetConstantValue ( nameArgumentOperation . Value . Syntax ) ;
274270 if ( ! constant . HasValue )
275271 {
276272 // not a constant value, we cannot correlate this invocation to an existent function in compile time
@@ -280,7 +276,7 @@ public override void Initialize(AnalysisContext context)
280276 return constant . Value ? . ToString ( ) ;
281277 }
282278
283- static IMethodSymbol ? FindOverridingMethod ( INamedTypeSymbol classSymbol , IMethodSymbol methodToFind )
279+ static bool ClassOverridesMethod ( INamedTypeSymbol classSymbol , IMethodSymbol methodToFind )
284280 {
285281 INamedTypeSymbol ? baseType = classSymbol ;
286282 while ( baseType != null )
@@ -289,20 +285,20 @@ public override void Initialize(AnalysisContext context)
289285 {
290286 if ( SymbolEqualityComparer . Default . Equals ( method . OverriddenMethod ? . OriginalDefinition , methodToFind ) )
291287 {
292- return method . OverriddenMethod ;
288+ return true ;
293289 }
294290 }
295291
296292 baseType = baseType . BaseType ;
297293 }
298294
299- return null ;
295+ return false ;
300296 }
301297
302- struct FunctionInvocation
298+ readonly struct FunctionInvocation ( string name , SyntaxNode invocationSyntaxNode )
303299 {
304- public string Name { get ; set ; }
300+ public string Name { get ; } = name ;
305301
306- public SyntaxNode InvocationSyntaxNode { get ; set ; }
302+ public SyntaxNode InvocationSyntaxNode { get ; } = invocationSyntaxNode ;
307303 }
308304}
0 commit comments