private void AnalyzeInvocation(SyntaxNodeAnalysisContext analysisContext)
        {
            var invocation = (InvocationExpressionSyntax)analysisContext.Node;

            var identifier = GetMethodCallIdentifier(invocation);

            if (identifier == null)
            {
                return;
            }

            var methodSignature = CheckedMethods.FirstOrDefault(method => method.Name.Equals(identifier.Value.ValueText));

            if (methodSignature == null)
            {
                return;
            }

            var methodCallSymbol = analysisContext.SemanticModel.GetSymbolInfo(identifier.Value.Parent);

            if (methodCallSymbol.Symbol == null ||
                !methodCallSymbol.Symbol.ContainingType.ConstructedFrom.Is(methodSignature.ContainingType))
            {
                return;
            }

            if (ShouldReportOnMethodCall(invocation, analysisContext.SemanticModel))
            {
                analysisContext.ReportDiagnostic(Diagnostic.Create(Rule, identifier.Value.GetLocation(),
                                                                   methodSignature.ToShortName()));
            }
        }
Beispiel #2
0
 private bool CanCompareMethods(MethodDefinition currentMethod, MethodDefinition targetMethod)
 {
     return(currentMethod.HasBody && targetMethod.HasBody &&
            !CheckedMethods.Contains(targetMethod.Name) &&
            currentMethod != targetMethod);
 }
 bool CanCompareMethods(MethodDefinition current, MethodDefinition target)
 {
     return(current.HasBody && target.HasBody &&
            !CheckedMethods.Contains(target.Name) &&
            current != target);
 }
 private MethodSignature FindDisallowedMethodSignature(SyntaxToken identifier, ISymbol methodCallSymbol)
 {
     return(CheckedMethods
            .Where(method => method.Name.Equals(identifier.ValueText))
            .FirstOrDefault(m => methodCallSymbol.ContainingType.ConstructedFrom.Is(m.ContainingType)));
 }