Пример #1
0
        public override void VisitArgument(ArgumentSyntax node)
        {
            var argumentExpr = node.Expression as MemberAccessExpressionSyntax;

            if (argumentExpr != null)
            {
                var argumentSymbol = _semantics.GetSymbolInfo(argumentExpr).Symbol as IPropertySymbol;
                if (argumentSymbol != null)
                {
                    if (RhinoRecognizer.IsAnythingProperty(argumentSymbol))
                    {
                        var innerSymbol = _semantics.GetSymbolInfo(argumentExpr.Expression).Symbol as IPropertySymbol;
                        if (RhinoRecognizer.IsIsArgProperty(innerSymbol))
                        {
                            SetTargetNode(argumentExpr);
                        }
                    }
                }
            }
            base.VisitArgument(node);
        }
        public override SyntaxNode VisitArgument(ArgumentSyntax node)
        {
            if (node.Expression is MemberAccessExpressionSyntax argumentExpr)
            {
                var argumentSymbol = _originalSemantics.GetSymbolInfo(argumentExpr).Symbol;
                if (argumentSymbol is IPropertySymbol propertySymbol)
                {
                    if (RhinoRecognizer.IsAnythingProperty(propertySymbol))
                    {
                        var innerSymbol = _originalSemantics.GetSymbolInfo(argumentExpr.Expression).Symbol as IPropertySymbol;
                        if (RhinoRecognizer.IsIsArgProperty(innerSymbol))
                        {
                            return(UseArgsAny(node));
                        }
                    }
                    if (RhinoRecognizer.IsNullArgProperty(propertySymbol))
                    {
                        var innerSymbol = _originalSemantics.GetSymbolInfo(argumentExpr.Expression).Symbol as IPropertySymbol;
                        if (RhinoRecognizer.IsIsArgProperty(innerSymbol))
                        {
                            return(UseArgWith(node, GetEqualsNullArgument(_methodContext.Current.UnusedLambdaToken)));
                        }
                    }
                    if (RhinoRecognizer.IsNotNullArgProperty(propertySymbol))
                    {
                        var innerSymbol = _originalSemantics.GetSymbolInfo(argumentExpr.Expression).Symbol as IPropertySymbol;
                        if (RhinoRecognizer.IsIsArgProperty(innerSymbol))
                        {
                            return(UseArgWith(node, GetNotEqualsNullArgument(_methodContext.Current.UnusedLambdaToken)));
                        }
                    }
                }

                if (node.RefKindKeyword.IsKind(SyntaxKind.OutKeyword) && argumentSymbol is IFieldSymbol fieldSymbol)
                {
                    if (RhinoRecognizer.IsDummyField(fieldSymbol))
                    {
                        var outMethodSymbol = _originalSemantics.GetSymbolInfo(argumentExpr.Expression).Symbol as IMethodSymbol;
                        if (RhinoRecognizer.IsOutArgMethod(outMethodSymbol) && argumentExpr.Expression is InvocationExpressionSyntax outMethodInvocation)
                        {
                            _invocationContext.Current.OutRefArguments.Add(outMethodInvocation.ArgumentList.Arguments.First().Expression);
                            return(UseArgsAny(node, true));
                        }
                    }
                }
            }

            if (node.Expression is InvocationExpressionSyntax argumentMethodInvocation)
            {
                var argumentSymbol = _originalSemantics.GetSymbolInfo(argumentMethodInvocation.Expression).Symbol;
                if (argumentSymbol is IMethodSymbol methodSymbol)
                {
                    if (RhinoRecognizer.IsEqualArgMethod(methodSymbol))
                    {
                        var equalsTo = argumentMethodInvocation.ArgumentList.Arguments.First().Expression;
                        return(UseArgWith(node, GetEqualsToGivenArgument(_methodContext.Current.UnusedLambdaToken, equalsTo)));
                    }
                    if (RhinoRecognizer.IsSameArgMethod(methodSymbol))
                    {
                        var sameTo = argumentMethodInvocation.ArgumentList.Arguments.First().Expression;
                        return(UseArgWith(node, GetReferenceEqualsToGivenArgument(_methodContext.Current.UnusedLambdaToken, sameTo)));
                    }
                    if (RhinoRecognizer.IsMatchesArgMethod(methodSymbol))
                    {
                        var lambdaArgument = argumentMethodInvocation.ArgumentList.Arguments.First().Expression;
                        return(UseArgWith(node, GetLambdaAsArgument(_methodContext.Current.UnusedLambdaToken, lambdaArgument)));
                    }
                }
            }

            return(base.VisitArgument(node));
        }