Esempio n. 1
0
        private bool MethodNameNotFound(MethodInformation methodInformation)
        {
            var invocationExpression = (InvocationExpressionSyntax)context.Node;
            var memberExpression     = invocationExpression.Expression as MemberAccessExpressionSyntax;

            return(memberExpression?.Name?.Identifier.ValueText != methodInformation.MethodName);
        }
Esempio n. 2
0
        private bool QualifiedConstructorNameNotFound(MethodInformation methodInformation)
        {
            var objectCreationExpressionSyntax = (ObjectCreationExpressionSyntax)context.Node;
            var identifier = objectCreationExpressionSyntax.Type as QualifiedNameSyntax;

            return(identifier?.Right.ToString() != methodInformation.MethodName);
        }
Esempio n. 3
0
        private bool AbreviatedConstructorNameNotFound(MethodInformation methodInformation)
        {
            var objectCreationExpressionSyntax = (ObjectCreationExpressionSyntax)context.Node;
            var identifier = objectCreationExpressionSyntax.Type as IdentifierNameSyntax;

            return(identifier?.Identifier.ValueText != methodInformation.MethodName);
        }
Esempio n. 4
0
        public void AnalyzeConstrutor(MethodInformation methodInformation)
        {
            if (ConstructorNameNotFound(methodInformation) || MethodFullNameNotFound(methodInformation.MethodFullDefinition))
            {
                return;
            }
            var argumentList = ((ObjectCreationExpressionSyntax)context.Node).ArgumentList;
            var arguments    = GetArguments(argumentList);

            Execute(methodInformation, arguments, argumentList);
        }
Esempio n. 5
0
        public void AnalyzeMethod(MethodInformation methodInformation)
        {
            if (MethodNameNotFound(methodInformation) ||
                MethodFullNameNotFound(methodInformation.MethodFullDefinition))
            {
                return;
            }
            var argumentList = ((InvocationExpressionSyntax)context.Node).ArgumentList;
            var arguments    = GetArguments(argumentList);

            Execute(methodInformation, arguments, argumentList);
        }
Esempio n. 6
0
 private void Execute(MethodInformation methodInformation, List <object> arguments, ArgumentListSyntax argumentList)
 {
     if (!argumentList.Arguments.Any())
     {
         return;
     }
     try
     {
         methodInformation.MethodAction.Invoke(arguments);
     }
     catch (Exception ex)
     {
         while (ex.InnerException != null)
         {
             ex = ex.InnerException;
         }
         var diag = Diagnostic.Create(diagnosticDescriptor, argumentList.Arguments[methodInformation.ArgumentIndex].GetLocation(), ex.Message);
         context.ReportDiagnostic(diag);
     }
 }
Esempio n. 7
0
 private bool ConstructorNameNotFound(MethodInformation methodInformation)
 {
     return(AbreviatedConstructorNameNotFound(methodInformation) && QualifiedConstructorNameNotFound(methodInformation));
 }