Esempio n. 1
0
        private static async Task <Document> FixCommentsAsync(Document document, LiteralExpressionSyntax stringLiteral, CancellationToken c)
        {
            var newValueText     = FixComments(stringLiteral.Token.ValueText, prefix: null);
            var oldText          = stringLiteral.Token.Text;
            var newText          = FixComments(oldText, getPrefix(oldText));
            var newStringLiteral = stringLiteral.Update(SyntaxFactory.Literal(text: newText, value: newValueText)).WithTriviaFrom(stringLiteral);

            var editor = await DocumentEditor.CreateAsync(document, c).ConfigureAwait(false);

            editor.ReplaceNode(stringLiteral, newStringLiteral);
            return(editor.GetChangedDocument());
Esempio n. 2
0
            public override SyntaxNode VisitLiteralExpression(LiteralExpressionSyntax node)
            {
                var pattern = $"[^\\w](?<before>{this.before}[^\\w])";

                if (node.IsKind(SyntaxKind.StringLiteralExpression) &&
                    Regex.IsMatch(node.Token.ValueText, pattern))
                {
                    return(node.Update(
                               SyntaxFactory.Literal(
                                   Regex.Replace(node.Token.Text, this.before, UpdateMatch),
                                   Regex.Replace(node.Token.ValueText, this.before, UpdateMatch))));
                }

                return(base.VisitLiteralExpression(node));

                string UpdateMatch(Match match)
                {
                    return(match.Value.Replace(this.before !, this.after));
                }
            }