public static string ReplaceStringLiteralsWithVariables(string text, IEnumerable<string> macros, Func<int, int, string, string, string> onReplace) { var sourceText = SourceText.From(text); var tree = CSharpSyntaxTree.ParseText(sourceText, new CSharpParseOptions(preprocessorSymbols: macros)); var newRoot = new StringLiteralToVariableRewriter() { OnRewrite = onReplace, Source = sourceText, }.Visit(tree.GetRoot()); return tree.WithRootAndOptions(newRoot, tree.Options).ToString(); }
public static string ReplaceStringLiteralsWithVariables(string text, IEnumerable <string> macros, Func <int, int, string, string> onReplace) { var tree = CSharpSyntaxTree.ParseText(text, new CSharpParseOptions(preprocessorSymbols: macros)); var newRoot = new StringLiteralToVariableRewriter() { OnRewrite = onReplace }.Visit(tree.GetRoot()); return(tree.WithRootAndOptions(newRoot, tree.Options).ToString()); }