Skip to content

Commit e0fb0ac

Browse files
committed
Check for target
1 parent cd1b021 commit e0fb0ac

1 file changed

Lines changed: 24 additions & 14 deletions

File tree

src/NServiceBus.AzureFunctions.Analyzer/AzureFunctionsConfigurationAnalyzer.cs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace NServiceBus.AzureFunctions.Analyzer
22
{
3+
using System;
34
using System.Collections.Immutable;
45
using Microsoft.CodeAnalysis;
56
using Microsoft.CodeAnalysis.CSharp;
@@ -23,22 +24,31 @@ public override void Initialize(AnalysisContext context)
2324

2425
static void Analyze(SyntaxNodeAnalysisContext context)
2526
{
27+
if (!(context.Node is InvocationExpressionSyntax invocationExpression))
28+
{
29+
return;
30+
}
31+
32+
if (!(invocationExpression.Expression is MemberAccessExpressionSyntax memberAccessExpression))
33+
{
34+
return;
35+
}
36+
37+
if (memberAccessExpression.Name.Identifier.Text != "PurgeOnStartup")
38+
{
39+
return;
40+
}
41+
42+
var memberAccessSymbol = context.SemanticModel.GetSymbolInfo(memberAccessExpression, context.CancellationToken);
43+
44+
if (!(memberAccessSymbol.Symbol is IMethodSymbol methodSymbol))
45+
{
46+
return;
47+
}
2648

27-
if (context.Node is InvocationExpressionSyntax invocationExpression)
49+
if (methodSymbol.ReceiverType.ToString() == "NServiceBus.EndpointConfiguration")
2850
{
29-
if (invocationExpression.Expression is MemberAccessExpressionSyntax memberAccessExpression)
30-
{
31-
if (memberAccessExpression.Name.Identifier.Text == "PurgeOnStartup")
32-
{
33-
if (memberAccessExpression.Expression is MemberAccessExpressionSyntax parentMemberAccessExpression)
34-
{
35-
if (parentMemberAccessExpression.Name.Identifier.Text == "AdvancedConfiguration")
36-
{
37-
context.ReportDiagnostic(AzureFunctionsDiagnostics.PurgeOnStartupNotAllowed, invocationExpression);
38-
}
39-
}
40-
}
41-
}
51+
context.ReportDiagnostic(AzureFunctionsDiagnostics.PurgeOnStartupNotAllowed, invocationExpression);
4252
}
4353
}
4454
}

0 commit comments

Comments
 (0)