Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo n.º 4
0
        private static void Analyzer(SyntaxNodeAnalysisContext context)
        {
            if (context.IsGenerated()) return;
            var mainConstrutor = new MethodInformation(
                nameof(Uri),
                "System.Uri.Uri(string)",
                args =>
                {
                    {
                        if (args[0] == null)
                        {
                            return;
                        }
                        new Uri(args[0].ToString());
                    }
                }
            );
            var constructorWithUriKind = new MethodInformation(
                nameof(Uri),
                "System.Uri.Uri(string, System.UriKind)",
                args =>
                {
                    if (args[0] == null)
                    {
                        return;
                    }
                    new Uri(args[0].ToString(), (UriKind)args[1]);
                }
            );

            var checker = new MethodChecker(context, Rule);
            checker.AnalyzeConstructor(mainConstrutor);
            checker.AnalyzeConstructor(constructorWithUriKind);
        }
Exemplo n.º 5
0
 public void AnalyzeConstructor(MethodInformation methodInformation)
 {
     if (ConstructorNameNotFound(methodInformation) || MethodFullNameNotFound(methodInformation.MethodFullDefinition))
         return;
     var argumentList = ((ObjectCreationExpressionSyntax)context.Node).ArgumentList;
     var arguments = GetArguments(argumentList);
     Execute(methodInformation, arguments, argumentList);
 }
Exemplo n.º 6
0
        public void AnalyzeConstructor(MethodInformation methodInformation)
        {
            if (ConstructorNameNotFound(methodInformation) || MethodFullNameNotFound(methodInformation.MethodFullDefinition))
            {
                return;
            }
            var argumentList = ((ObjectCreationExpressionSyntax)context.Node).ArgumentList;
            var arguments    = GetArguments(argumentList);

            Execute(methodInformation, arguments, argumentList);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
 private static void Analyzer(SyntaxNodeAnalysisContext context)
 {
     if (context.IsGenerated()) return;
     var method = new MethodInformation(
         "Parse",
         "System.Net.IPAddress.Parse(string)",
         args =>
         {
             parseMethodInfo.Value.Invoke(null, new[] { args[0].ToString() });
         }
         );
     var checker = new MethodChecker(context, Rule);
     checker.AnalyzeMethod(method);
 }
Exemplo n.º 10
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);
     }
 }
Exemplo n.º 11
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);
     }
 }
Exemplo n.º 12
0
 private bool MethodNameNotFound(MethodInformation methodInformation)
 {
     var invocationExpression = (InvocationExpressionSyntax)context.Node;
     var memberExpression = invocationExpression.Expression as MemberAccessExpressionSyntax;
     return memberExpression?.Name?.Identifier.ValueText != methodInformation.MethodName;
 }
Exemplo n.º 13
0
 private bool QualifiedConstructorNameNotFound(MethodInformation methodInformation)
 {
     var objectCreationExpressionSyntax = (ObjectCreationExpressionSyntax)context.Node;
     var identifier = objectCreationExpressionSyntax.Type as QualifiedNameSyntax;
     return identifier?.Right.ToString() != methodInformation.MethodName;
 }
Exemplo n.º 14
0
 private bool AbreviatedConstructorNameNotFound(MethodInformation methodInformation)
 {
     var objectCreationExpressionSyntax = (ObjectCreationExpressionSyntax) context.Node;
     var identifier = objectCreationExpressionSyntax.Type as IdentifierNameSyntax;
     return identifier?.Identifier.ValueText != methodInformation.MethodName;
 }
Exemplo n.º 15
0
 private bool ConstructorNameNotFound(MethodInformation methodInformation)
 {
     return AbreviatedConstructorNameNotFound(methodInformation) && QualifiedConstructorNameNotFound(methodInformation);
 }
Exemplo n.º 16
0
 private bool ConstructorNameNotFound(MethodInformation methodInformation)
 {
     return(AbreviatedConstructorNameNotFound(methodInformation) && QualifiedConstructorNameNotFound(methodInformation));
 }