示例#1
0
        public static (SyntaxTree Tree, string[] ClassNames, string formatter, IEnumerable <Diagnostic> errors) GetTreeInfo(string content)
        {
            SyntaxTree            tree = CSharpSyntaxTree.ParseText(content, new CSharpParseOptions(LanguageVersion.Latest));
            CompilationUnitSyntax root = tree.GetCompilationUnitRoot();


            root = (CompilationUnitSyntax)Formatter.Format(root, _workSpace);
            var errors    = root.GetDiagnostics();
            var formatter = root.ToString();


            var result = new List <string>(from typeNodes
                                           in root.DescendantNodes().OfType <ClassDeclarationSyntax>()
                                           select typeNodes.Identifier.Text);

            result.AddRange(from typeNodes
                            in root.DescendantNodes().OfType <StructDeclarationSyntax>()
                            select typeNodes.Identifier.Text);

            result.AddRange(from typeNodes
                            in root.DescendantNodes().OfType <InterfaceDeclarationSyntax>()
                            select typeNodes.Identifier.Text);

            result.AddRange(from typeNodes
                            in root.DescendantNodes().OfType <EnumDeclarationSyntax>()
                            select typeNodes.Identifier.Text);


            return(root.SyntaxTree, result.ToArray(), formatter, errors);
        }
示例#2
0
        private static void TestRoundTripping(CompilationUnitSyntax node, string text, bool disallowErrors = true)
        {
            Assert.That(node, Is.Not.Null);
            var fullText = node.ToFullString();

            Assert.That(fullText, Is.EqualTo(text));

            if (disallowErrors)
            {
                Assert.That(node.GetDiagnostics(), Is.Empty);
            }
            else
            {
                Assert.That(node.GetDiagnostics(), Is.Not.Empty);
            }
        }
示例#3
0
        public static void Deconstruct(
            this string text,
            out SyntaxTree tree,
            out string formatter,
            out IEnumerable <Diagnostic> errors)
        {
            text = text.Trim();
            tree = CSharpSyntaxTree.ParseText(text, new CSharpParseOptions(LanguageVersion.Latest));
            CompilationUnitSyntax root = tree.GetCompilationUnitRoot();


            root      = (CompilationUnitSyntax)Formatter.Format(root, _workSpace);
            tree      = root.SyntaxTree;
            formatter = root.ToString();
            errors    = root.GetDiagnostics();
        }
示例#4
0
        private static void TestRoundTripping(CompilationUnitSyntax node, string text, bool disallowErrors = true)
        {
            Assert.That(node, Is.Not.Null);
            var fullText = node.ToFullString();
            Assert.That(fullText, Is.EqualTo(text));

            if (disallowErrors)
                Assert.That(node.GetDiagnostics(), Is.Empty);
            else
                Assert.That(node.GetDiagnostics(), Is.Not.Empty);
        }