Created
July 26, 2014 18:47
-
-
Save JoshVarty/3958c01c7e78e003ee2a to your computer and use it in GitHub Desktop.
This file contains 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
public class ClassMethodWalker : CSharpSyntaxWalker | |
{ | |
string className = String.Empty; | |
public override void VisitClassDeclaration(ClassDeclarationSyntax node) | |
{ | |
className = node.Identifier.ToString(); | |
base.VisitClassDeclaration(node); | |
} | |
public override void VisitMethodDeclaration(MethodDeclarationSyntax node) | |
{ | |
string methodName = node.Identifier.ToString(); | |
Console.WriteLine(className + '.' + methodName); | |
base.VisitMethodDeclaration(node); | |
} | |
} | |
static void Main(string[] args) | |
{ | |
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()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment