Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Just testing git hub");

            // TODO: changes this to relative path
            var myClassText = File.ReadAllText(@"d:\src\GitHub\Repos\Roslyn-tinkering\ConsoleApplication1\MyClass.cs");
            var tree = CSharpSyntaxTree.ParseText(myClassText);

            var syntaxRoot = tree.GetRoot();
            var myMethods = syntaxRoot.DescendantNodes()
                .OfType<MethodDeclarationSyntax>();

            // gets all methods from class
            foreach (var myMethod in myMethods)
            {
                Console.WriteLine(myMethod.Identifier.ToString());
            }

            var customWalker = new CustomWalker();
            customWalker.Visit(syntaxRoot);

            // another way to get all methods
            var classMethodWalker = new ClassMethodWalker();
            classMethodWalker.Visit(syntaxRoot);

            Console.WriteLine("New class without semicolons.");
            var rewriter = new EmptyStatementRemoval();
            var result = rewriter.Visit(tree.GetRoot());
            Console.WriteLine(result.ToFullString());

            Console.ReadKey();
        }
Exemplo n.º 2
0
    public void _3PrintConcatenationClassAndMethod()
    {
        var tree = CSharpSyntaxTree.ParseText(@"
            public class MyClass
            {
                public void MyMethod()
                {
                }
            }
            public class MyOtherClass
            {
                public void MyMethod(int n)
                {
                }
            }
           ");

        var walker = new ClassMethodWalker();

        walker.Visit(tree.GetRoot());
    }