예제 #1
0
        protected ExpressionSyntax GetNewExpression(ExpressionSyntax expression, NodeReplacement replacement)
        {
            var visitor = new MemberAccessExpressionsCSharpSyntaxVisitor();

            expression.Accept(visitor);
            var members = new LinkedList <MemberAccessExpressionSyntax>(visitor.Members);

            var current = members.Last;

            while (current != null)
            {
                if (replacement.IsValidNode(current))
                {
                    // extract custom data into the replacement object
                    replacement.ExtractValues(current.Value);

                    var oldNode = replacement.ComputeOld(current);
                    var newNode = replacement.ComputeNew(current);
                    return(expression.ReplaceNode(oldNode, newNode));
                }
                current = current.Previous;
            }

            throw new System.InvalidOperationException("should not get here");
        }
            public override bool IsValid(ExpressionSyntax expression)
            {
                if (!base.IsValid(expression))
                {
                    return(false);
                }

                var visitor = new MemberAccessExpressionsCSharpSyntaxVisitor();

                expression.Accept(visitor);

                var containKey   = visitor.Members.Find(member => member.Name.Identifier.Text == "ContainKey");
                var containValue = visitor.Members.Find(member => member.Name.Identifier.Text == "ContainValue");

                return(containKey.Parent is InvocationExpressionSyntax keyInvocation &&
                       containValue.Parent is InvocationExpressionSyntax valueInvocation

                       && keyInvocation.ArgumentList.Arguments is SeparatedSyntaxList <ArgumentSyntax> containKeyArguments &&
                       valueInvocation.ArgumentList.Arguments is SeparatedSyntaxList <ArgumentSyntax> containValueArguments

                       && containKeyArguments.First().Expression is MemberAccessExpressionSyntax keyArgument &&
                       containValueArguments.First().Expression is MemberAccessExpressionSyntax valueArgument

                       && keyArgument.Expression is IdentifierNameSyntax keyIdentifier &&
                       valueArgument.Expression is IdentifierNameSyntax valueIdentifier

                       && keyIdentifier.Identifier.Text == valueIdentifier.Identifier.Text);
            }
예제 #3
0
        protected override bool CanRewriteAssertion(ExpressionSyntax expression)
        {
            var visitor = new MemberAccessExpressionsCSharpSyntaxVisitor();

            expression.Accept(visitor);

            var beLessOrEqualTo    = visitor.Members.Find(member => member.Name.Identifier.Text == "BeLessOrEqualTo");
            var beGreaterOrEqualTo = visitor.Members.Find(member => member.Name.Identifier.Text == "BeGreaterOrEqualTo");

            return(!(beLessOrEqualTo.Parent is InvocationExpressionSyntax beLessOrEqualToInvocation && beLessOrEqualToInvocation.ArgumentList.Arguments.Count > 1 &&
                     beGreaterOrEqualTo.Parent is InvocationExpressionSyntax beGreaterOrEqualToInvocation && beGreaterOrEqualToInvocation.ArgumentList.Arguments.Count > 1));
        }
예제 #4
0
        protected override bool CanRewriteAssertion(ExpressionSyntax expression)
        {
            var visitor = new MemberAccessExpressionsCSharpSyntaxVisitor();

            expression.Accept(visitor);

            var containKey   = visitor.Members.Find(member => member.Name.Identifier.Text == "ContainKey");
            var containValue = visitor.Members.Find(member => member.Name.Identifier.Text == "ContainValue");

            return(!(containKey.Parent is InvocationExpressionSyntax containKeyInvocation && containKeyInvocation.ArgumentList.Arguments.Count > 1 &&
                     containValue.Parent is InvocationExpressionSyntax containValueInvocation && containValueInvocation.ArgumentList.Arguments.Count > 1));
        }
        protected override bool CanRewriteAssertion(ExpressionSyntax expression)
        {
            var visitor = new MemberAccessExpressionsCSharpSyntaxVisitor();

            expression.Accept(visitor);

            var notBeEmpty = visitor.Members.Find(member => member.Name.Identifier.Text == "NotBeEmpty");
            var notBeNull  = visitor.Members.Find(member => member.Name.Identifier.Text == "NotBeNull");

            return(!(notBeEmpty.Parent is InvocationExpressionSyntax notBeEmptyInvocation && notBeEmptyInvocation.ArgumentList.Arguments.Any() &&
                     notBeNull.Parent is InvocationExpressionSyntax notBeNullInvocation && notBeNullInvocation.ArgumentList.Arguments.Any()));
        }