private void AnalyzeMemberAccessExpressionsVb(SyntaxNodeAnalysisContext context)
        {
            var memberAccessExpression = (VBSyntax.MemberAccessExpressionSyntax)context.Node;

            // If the accessed member isn't named "Current" bail out
            if (!TargetMember.Equals(memberAccessExpression.Name.Identifier.ValueText, StringComparison.Ordinal))
            {
                return;
            }

            // If the call is to a method called Current then bail out since they're
            // not using the HttpContext.Current property
            if (memberAccessExpression.Parent is VBSyntax.InvocationExpressionSyntax)
            {
                return;
            }

            // Get the identifier accessed
            var accessedIdentifier = memberAccessExpression.Expression switch
            {
                VBSyntax.IdentifierNameSyntax i => i,
                VBSyntax.MemberAccessExpressionSyntax m => m.DescendantNodes().OfType <VBSyntax.IdentifierNameSyntax>().LastOrDefault(),
                _ => null
            };

            AnalyzeMemberAccessExpressions(context, memberAccessExpression, accessedIdentifier, accessedIdentifier?.Identifier.ValueText);
        }
예제 #2
0
        bool TryConvertRaiseEvent(CSS.IfStatementSyntax node, out IdentifierNameSyntax name, List <ArgumentSyntax> arguments)
        {
            name = null;
            var condition = node.Condition;

            while (condition is CSS.ParenthesizedExpressionSyntax)
            {
                condition = ((CSS.ParenthesizedExpressionSyntax)condition).Expression;
            }
            if (!(condition is CSS.BinaryExpressionSyntax))
            {
                return(false);
            }
            var be = (CSS.BinaryExpressionSyntax)condition;

            if (!be.IsKind(CS.SyntaxKind.NotEqualsExpression) || (!be.Left.IsKind(CS.SyntaxKind.NullLiteralExpression) && !be.Right.IsKind(CS.SyntaxKind.NullLiteralExpression)))
            {
                return(false);
            }
            CSS.ExpressionStatementSyntax singleStatement;
            if (node.Statement is CSS.BlockSyntax)
            {
                var block = ((CSS.BlockSyntax)node.Statement);
                if (block.Statements.Count != 1)
                {
                    return(false);
                }
                singleStatement = block.Statements[0] as CSS.ExpressionStatementSyntax;
            }
            else
            {
                singleStatement = node.Statement as CSS.ExpressionStatementSyntax;
            }
            if (singleStatement == null || !(singleStatement.Expression is CSS.InvocationExpressionSyntax))
            {
                return(false);
            }
            var possibleEventName = GetPossibleEventName(be.Left) ?? GetPossibleEventName(be.Right);

            if (possibleEventName == null)
            {
                return(false);
            }
            var invocation     = (CSS.InvocationExpressionSyntax)singleStatement.Expression;
            var invocationName = GetPossibleEventName(invocation.Expression);

            if (possibleEventName != invocationName)
            {
                return(false);
            }
            name = SyntaxFactory.IdentifierName(possibleEventName);
            arguments.AddRange(invocation.ArgumentList.Arguments.Select(a => (ArgumentSyntax)a.Accept(_nodesVisitor)));
            return(true);
        }