By redundant stuff, I mean the namespaces, as I know they are necessary but if there are 10k of them, it doesn't add valuable info to the table.
Could this be done using Linq?
By redundant stuff, I mean the namespaces, as I know they are necessary but if there are 10k of them, it doesn't add valuable info to the table.
Could this be done using Linq?
Visual studio will do this for you. Right click on your project and choose Calculate Code Metrics
.
No need to reinvent the wheel. Take a look at the Visual Studio Code Metrics PowerTool 11.0
Overview
The Code Metrics PowerTool is a command line utility that calculates code metrics for your managed code and saves them to an XML file. This tool enables teams to collect and report code metrics as part of their build process. The code metrics calculated are:
• Maintainability Index
• Cyclomatic Complexity
• Depth of Inheritance
• Class Coupling
• Lines Of Code (LOC)
I know you said you don't have Ultimate, so I just wanted to show you what you're missing.
For everyone else, there's SourceMonitor
From: http://rajputyh.blogspot.in/2014/02/counting-number-of-real-lines-in-your-c.html
private int CountNumberOfLinesInCSFilesOfDirectory(string dirPath)
{
FileInfo[] csFiles = new DirectoryInfo(dirPath.Trim())
.GetFiles("*.cs", SearchOption.AllDirectories);
int totalNumberOfLines = 0;
Parallel.ForEach(csFiles, fo =>
{
Interlocked.Add(ref totalNumberOfLines, CountNumberOfLine(fo));
});
return totalNumberOfLines;
}
private int CountNumberOfLine(Object tc)
{
FileInfo fo = (FileInfo)tc;
int count = 0;
int inComment = 0;
using (StreamReader sr = fo.OpenText())
{
string line;
while ((line = sr.ReadLine()) != null)
{
if (IsRealCode(line.Trim(), ref inComment))
count++;
}
}
return count;
}
private bool IsRealCode(string trimmed, ref int inComment)
{
if (trimmed.StartsWith("/*") && trimmed.EndsWith("*/"))
return false;
else if (trimmed.StartsWith("/*"))
{
inComment++;
return false;
}
else if (trimmed.EndsWith("*/"))
{
inComment--;
return false;
}
return
inComment == 0
&& !trimmed.StartsWith("//")
&& (trimmed.StartsWith("if")
|| trimmed.StartsWith("else if")
|| trimmed.StartsWith("using (")
|| trimmed.StartsWith("else if")
|| trimmed.Contains(";")
|| trimmed.StartsWith("public") //method signature
|| trimmed.StartsWith("private") //method signature
|| trimmed.StartsWith("protected") //method signature
);
}
I have no solid idea about them, but you can use Code Metrics Values to get some statistics about your solution, like code lines.
we have used the tfs cube to get the data about how many lines add/delete/change on our tfs. This one you can view from excel. But need to configure it properly. And I don't think it will exclude the comments and blank lines etc.
Ctrl+Shift+f (Find in files) -> put ";" in the "Find what:"-textbox -> Press "Find All"-button.
This extremly simple method makes use of the fact, that any C# statement is terminated with a semicolon. And, at least I dont't use semicolons at any other place (e.g. in comments)...
class Foo {
, void Foo() {
, IReadOnlyList<int> Foo {
, etc.
As mentioned above but in easy way
from solution explorer right click your project.
select "analyze and code cleanup".
select calculate code metrics
then you will get all information such as all code lines