Created
July 6, 2014 21:17
-
-
Save JoshVarty/e377af43df8775559c03 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
var tree = CSharpSyntaxTree.ParseText(@" | |
public class MyClass | |
{ | |
public void MyMethod() | |
{ | |
} | |
public void MyMethod(int n) | |
{ | |
} | |
}"); | |
var syntaxRoot = tree.GetRoot(); | |
var MyMethod = syntaxRoot.DescendantNodes().OfType<MethodDeclarationSyntax>() | |
.Where(n => n.ParameterList.Parameters.Any()).First(); | |
var containingType = MyMethod.Ancestors().OfType<ClassDeclarationSyntax>().First(); | |
Console.WriteLine(containingType.Identifier.ToString()); | |
Console.WriteLine(MyMethod.ToString()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment