@@ -18,7 +18,9 @@ public class AzureFunctionsConfigurationAnalyzer : DiagnosticAnalyzer
1818 AzureFunctionsDiagnostics . SetDiagnosticsPathNotAllowed ,
1919 AzureFunctionsDiagnostics . MakeInstanceUniquelyAddressableNotAllowed ,
2020 AzureFunctionsDiagnostics . UseTransportNotAllowed ,
21- AzureFunctionsDiagnostics . OverrideLocalAddressNotAllowed
21+ AzureFunctionsDiagnostics . OverrideLocalAddressNotAllowed ,
22+ AzureFunctionsDiagnostics . RouteReplyToThisInstanceNotAllowed ,
23+ AzureFunctionsDiagnostics . RouteToThisInstanceNotAllowed
2224 ) ;
2325
2426 static readonly Dictionary < string , DiagnosticDescriptor > NotAllowedEndpointConfigurationMethods
@@ -33,6 +35,12 @@ static readonly Dictionary<string, DiagnosticDescriptor> NotAllowedEndpointConfi
3335 [ "OverrideLocalAddress" ] = AzureFunctionsDiagnostics . OverrideLocalAddressNotAllowed ,
3436 } ;
3537
38+ static readonly Dictionary < string , DiagnosticDescriptor > NotAllowedSendAndReplyOptions
39+ = new Dictionary < string , DiagnosticDescriptor >
40+ {
41+ [ "RouteReplyToThisInstance" ] = AzureFunctionsDiagnostics . RouteReplyToThisInstanceNotAllowed ,
42+ [ "RouteToThisInstance" ] = AzureFunctionsDiagnostics . RouteToThisInstanceNotAllowed
43+ } ;
3644
3745 public override void Initialize ( AnalysisContext context )
3846 {
@@ -53,6 +61,13 @@ static void Analyze(SyntaxNodeAnalysisContext context)
5361 return ;
5462 }
5563
64+ AnalyzeEndpointConfiguration ( context , invocationExpression , memberAccessExpression ) ;
65+
66+ AnalyzeSendAndReplyOptions ( context , invocationExpression , memberAccessExpression ) ;
67+ }
68+
69+ static void AnalyzeEndpointConfiguration ( SyntaxNodeAnalysisContext context , InvocationExpressionSyntax invocationExpression , MemberAccessExpressionSyntax memberAccessExpression )
70+ {
5671 if ( ! NotAllowedEndpointConfigurationMethods . TryGetValue ( memberAccessExpression . Name . Identifier . Text , out var diagnosticDescriptor ) )
5772 {
5873 return ;
@@ -70,5 +85,25 @@ static void Analyze(SyntaxNodeAnalysisContext context)
7085 context . ReportDiagnostic ( diagnosticDescriptor , invocationExpression ) ;
7186 }
7287 }
88+
89+ static void AnalyzeSendAndReplyOptions ( SyntaxNodeAnalysisContext context , InvocationExpressionSyntax invocationExpression , MemberAccessExpressionSyntax memberAccessExpression )
90+ {
91+ if ( ! NotAllowedSendAndReplyOptions . TryGetValue ( memberAccessExpression . Name . Identifier . Text , out var diagnosticDescriptor ) )
92+ {
93+ return ;
94+ }
95+
96+ var memberAccessSymbol = context . SemanticModel . GetSymbolInfo ( memberAccessExpression , context . CancellationToken ) ;
97+
98+ if ( ! ( memberAccessSymbol . Symbol is IMethodSymbol methodSymbol ) )
99+ {
100+ return ;
101+ }
102+
103+ if ( methodSymbol . ReceiverType . ToString ( ) == "NServiceBus.SendOptions" || methodSymbol . ReceiverType . ToString ( ) == "NServiceBus.ReplyOptions" )
104+ {
105+ context . ReportDiagnostic ( diagnosticDescriptor , invocationExpression ) ;
106+ }
107+ }
73108 }
74109}
0 commit comments