Esempio n. 1
0
        public override SyntaxNode VisitLocalDeclarationStatement(LocalDeclarationStatementSyntax node)
        {
            node = (LocalDeclarationStatementSyntax)base.VisitLocalDeclarationStatement(node);

            var initializer = node.Declaration
                              .Descendants <EqualsValueClauseSyntax>()
                              .FirstOrDefault();

            var memberAccess = initializer?
                               .Descendants <MemberAccessExpressionSyntax>()
                               .FirstOrDefault();

            if (memberAccess != null &&
                _context.GetNodeContainingClassType(memberAccess) == _type &&
                memberAccess.Name.ToString() == _memberName)
            {
                var newMemberAccess = node.Declaration
                                      .WithType(
                    SyntaxFactory.ParseTypeName(_returnType)
                    .WithTriviaFrom(node.Declaration.Type));

                node = node.ReplaceNode(node.Declaration, newMemberAccess);

                _context.UpdateNodeType(newMemberAccess, _returnType);
            }

            return(node);
        }
        private bool MethodMatches(ExpressionSyntax node)
        {
            var type = _context.GetNodeContainingClassType(node);

            return(type == _oldMethod.Type &&
                   GetMethodIdentifier(node).ToString() == _oldMethod.Name);
            //&& ArgumentsMatch(info.Arguments, _oldMethod.Arguments);
        }
Esempio n. 3
0
        public override SyntaxNode VisitObjectCreationExpression(ObjectCreationExpressionSyntax node)
        {
            node = (ObjectCreationExpressionSyntax)base.VisitObjectCreationExpression(node);
            if (_context.GetNodeContainingClassType(node) == _type)
            {
                node = node.WithArgumentList(
                    CreateArgumentList(
                        _constructorArguments,
                        node.ArgumentList.CloseParenToken.LeadingTrivia,
                        node.ArgumentList.CloseParenToken.TrailingTrivia));
            }

            return(node);
        }
        public override SyntaxNode VisitMemberAccessExpression(MemberAccessExpressionSyntax node)
        {
            node = (MemberAccessExpressionSyntax)base.VisitMemberAccessExpression(node);

            var type = _context.GetNodeContainingClassType(node);

            if (type == _type && node.Name.ToString() == _memberName)
            {
                node = node
                       .WithName(SyntaxFactory.IdentifierName(_newName))
                       .WithLeadingTrivia(node.GetLeadingTrivia())
                       .WithTrailingTrivia(node.GetTrailingTrivia());

                node = node.CopyAnnotationsTo(node);
            }

            return(node);
        }