private static void Test( string sourceText, bool useDefaultFormatting, bool removeRedundantCalls, bool shortenCodeWithUsingStatic, NodeKind nodeKind = NodeKind.CompilationUnit) { if (useDefaultFormatting) { sourceText = CSharpSyntaxTree .ParseText(sourceText) .GetRoot() .NormalizeWhitespace() .ToFullString(); } var quoter = new Quoter { UseDefaultFormatting = useDefaultFormatting, RemoveRedundantModifyingCalls = removeRedundantCalls, }; var generatedCode = quoter.Quote(sourceText, nodeKind); var resultText = quoter.Evaluate(generatedCode); if (sourceText != resultText) { //File.WriteAllText(@"D:\1.txt", sourceText); //File.WriteAllText(@"D:\2.txt", resultText); //File.WriteAllText(@"D:\3.txt", generatedCode); } Assert.Equal(sourceText, resultText); }
static void Main(string[] args) { var sourceText = "class C{}"; var sourceNode = CSharpSyntaxTree.ParseText(sourceText).GetRoot() as CSharpSyntaxNode; var quoter = new Quoter { OpenParenthesisOnNewLine = false, ClosingParenthesisOnNewLine = false, UseDefaultFormatting = true }; var generatedNode = quoter.Quote(sourceNode); var generatedCode = quoter.Print(generatedNode); var code = quoter.Evaluate(generatedNode); Console.WriteLine(generatedCode); }
private static void Test(string sourceText, bool useDefaultFormatting, bool removeRedundantCalls, bool shortenCodeWithUsingStatic) { if (useDefaultFormatting) { sourceText = CSharpSyntaxTree .ParseText(sourceText) .GetRoot() .NormalizeWhitespace() .ToFullString(); } var quoter = new Quoter { UseDefaultFormatting = useDefaultFormatting, RemoveRedundantModifyingCalls = removeRedundantCalls }; var generatedCode = quoter.Quote(sourceText); var resultText = quoter.Evaluate(generatedCode); if (sourceText != resultText) { //File.WriteAllText(@"D:\1.txt", sourceText); //File.WriteAllText(@"D:\2.txt", resultText); //File.WriteAllText(@"D:\3.txt", generatedCode); } Assert.AreEqual(sourceText, resultText); }