Created
October 10, 2014 08:39
-
-
Save sudipto80/824c84bac10a9e1e3780 to your computer and use it in GitHub Desktop.
Meta Programming using Roslyn (Finding LoC for all the methods)
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
SyntaxTree tree = SyntaxTree.ParseText(@"int fun(int x){ int y = 10; x++; | |
if(x>20) x -= y; return x+1;} | |
double funny(double x){ int s = 3; double t = 4; | |
return x + s * t/2.13;}"); | |
List<MethodDeclarationSyntax> methods = tree.GetRoot() | |
.DescendantNodes() | |
.Where(d => d.Kind == SyntaxKind.MethodDeclaration) | |
.Cast<MethodDeclarationSyntax>().ToList(); | |
int lvc = methods[0].Body.Statements.Count(x => x.Kind == SyntaxKind.LocalDeclarationStatement); | |
methods.Select(z => new { MethodName = z.Identifier.ValueText, LoC = z.Body.Statements.Count }) | |
.OrderByDescending(x => x.LoC) | |
.ToList() | |
.ForEach(x => Console.WriteLine(x.MethodName + " " + x.LoC)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment