protected void Analyze(SyntaxNodeAnalysisContext syntaxNodeAnalysisContext, SyntaxNode syntaxNode, ISymbol symbol = null) { var analysisResult = _nonSubstitutableMemberAnalysis.Analyze(syntaxNodeAnalysisContext, syntaxNode, symbol); if (analysisResult.CanBeSubstituted == false) { ReportDiagnostics(syntaxNodeAnalysisContext, in analysisResult); } }
private void AnalyzeArgLikeMethod(SyntaxNodeAnalysisContext syntaxNodeContext, TInvocationExpressionSyntax argInvocationExpression) { // find allowed enclosing expression var enclosingExpression = FindAllowedEnclosingExpression(argInvocationExpression); // if Arg is used with not allowed expression, find if it is used in ignored ones eg. var x = Arg.Any // as variable might be used later on if (enclosingExpression == null) { var maybeIgnoredEnclosingExpression = FindMaybeIgnoredEnclosingExpression(argInvocationExpression); if (maybeIgnoredEnclosingExpression == null) { var diagnostic = Diagnostic.Create( DiagnosticDescriptorsProvider.NonSubstitutableMemberArgumentMatcherUsage, argInvocationExpression.GetLocation()); syntaxNodeContext.ReportDiagnostic(diagnostic); return; } } if (enclosingExpression == null) { return; } if (syntaxNodeContext.SemanticModel.GetOperation(enclosingExpression).IsEventAssignmentOperation()) { return; } var enclosingExpressionSymbol = syntaxNodeContext.SemanticModel.GetSymbolInfo(enclosingExpression).Symbol; if (enclosingExpressionSymbol == null) { return; } var analysisResult = _nonSubstitutableMemberAnalysis.Analyze(syntaxNodeContext, enclosingExpression); if (analysisResult.CanBeSubstituted == false) { var diagnostic = Diagnostic.Create( DiagnosticDescriptorsProvider.NonSubstitutableMemberArgumentMatcherUsage, argInvocationExpression.GetLocation()); syntaxNodeContext.TryReportDiagnostic(diagnostic, enclosingExpressionSymbol); } }