Created
July 6, 2014 21:21
-
-
Save JoshVarty/37b27f698fd8905cfda2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.CodeAnalysis.CSharp; | |
using Microsoft.CodeAnalysis.CSharp.Syntax; | |
var tree = CSharpSyntaxTree.ParseText(@" | |
public class MyClass | |
{ | |
public void MyMethod() | |
{ | |
} | |
}"); | |
var syntaxRoot = tree.GetRoot(); | |
var MyClass = syntaxRoot.DescendantNodes().OfType<ClassDeclarationSyntax>().First(); | |
var MyMethod = syntaxRoot.DescendantNodes().OfType<MethodDeclarationSyntax>().First(); | |
Console.WriteLine(MyClass.Identifier.ToString()); | |
Console.WriteLine(MyMethod.Identifier.ToString()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had to add
using System.Linq
to bring .OfType() into scope