示例#1
0
    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);
    }
示例#2
0
        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);
        }
示例#3
0
    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);
    }