private CodeLinesCounter CountNumberOfLine(FileInfo tc) { var counter = new CodeLinesCounter(); var fo = tc; int inComment = 0; using (var sr = fo.OpenText()) { string line; while ((line = sr.ReadLine()) != null) { counter.CodeLines++; counter.PhysicalLines++; var trimmed = line.Trim(); if (string.IsNullOrWhiteSpace(trimmed)) { counter.EmptyLines++; } //if (trimmed.Contains("{") || trimmed.Contains("}") || trimmed.Contains("#")) // counter.CurlyBracesAndSharpLines++; if (IsRealCode(trimmed, ref inComment)) { counter.LogicalLines++; counter.LogicalLines += CountFuncCalls(trimmed); } else if (inComment > 0 || trimmed.StartsWith("//") || trimmed.Contains("//")) { counter.CommentLines++; } } } if (counter.PhysicalLines < counter.EmptyLines * 4) { counter.PhysicalLines -= counter.EmptyLines * 4 - counter.PhysicalLines; } return(counter); }
public CodeLinesCounter CountNumberOfLinesInCSFilesOfDirectory(string dirPath) { var csFiles = new DirectoryInfo(dirPath.Trim()) .GetFiles("*.cs", SearchOption.AllDirectories); var tCounter = new CodeLinesCounter(); foreach (var fileInfo in csFiles) { var counter = CountNumberOfLine(fileInfo); tCounter.EmptyLines += counter.EmptyLines; tCounter.CodeLines += counter.CodeLines; tCounter.CommentLines += counter.CommentLines; tCounter.PhysicalLines += counter.PhysicalLines; tCounter.LogicalLines += counter.LogicalLines; //tCounter.CurlyBracesAndSharpLines += counter.CurlyBracesAndSharpLines; } return(tCounter); }