score:35
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
score:0
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)...
score:1
i have no solid idea about them, but you can use code metrics values to get some statistics about your solution, like code lines.
score:1
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.
score:3
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
);
}
- comments of // and /* kind are ignored.
- a statement written in multiple line is considered single line.
- brackets are (i.e. '{') not considered lines.
- 'using namespace' line are ignored.
- lines which are class name etc. are ignored.
score:34
visual studio will do this for you. right click on your project and choose calculate code metrics
.
Source: stackoverflow.com
Related Query
- How to count the number of code lines in a C# solution, without comments and empty lines, and other redundant stuff, etc?
- How to group and count the number of occurence of item in comma delimited string
- How to count the occurence of each number in list A that is exist in list B and return zero if not existed?
- How can I check the number of calls to the database in LINQ query when using .NET Core and Code First?
- How do I Count the number of parent groups using LINQ and child repo
- How to count the number of elements that match a condition with LINQ
- How do I count the number of child collection's items using LINQ Method Syntax?
- DataTable: how to get the duplicates and the row number of the duplicates
- How to group by multiple fields and get the count of another field
- How to return partial results and the total count for a query with Entity Framework?
- How can I write an UPDATE in LINQ without fetching the object, changing it, and calling SaveChanges?
- Best way to join 3 lists and count how many times an ID is in the list using linq
- How to group by list of values and then count the amount of entries per value
- How to change the precision and the scale of decimal globally through code first?
- How to get the distinct record name and its each record count to bind to gridview in C# using Linq from SQL Server
- How to count the number of dates in a dateTime list
- How Do I count the number of occurrences in the IEnumerable
- How to join two tables using Linq and count the rows of one column matched records
- How can I select the most recent and distinct records and then count the different result types using LINQ?
- How to add an item to the repository without loading the item's Parent and siblings into memory
- How to use Group by of two elements in an object and get the count in List?
- How do I count the number of records with no match on the right side of a Linq left join?
- c# - How to count the number of occurences of a string in a ReadOnlyCollection field
- How do I count the number of items > 0 in a Dictionary<string, int> using Linq in C#/.Net?
- How to compare the dates and gets the day count using c# in LINQ
- How can I display the total number of records a table holds(the count) in a view by passing the count value in the "return view method"
- How to count write the linq query when the grouped bY column is in one table and the items are in another table
- How to get only the date value from DateTime and count it?
- how to count the number of items contains in list in C# or linq
- How can I count total item in an object/record and count only the value = true
More Query from same tag
- Get distinct list of choices from a multiple choice field's data?
- Sort List<T> Property every time an item is added
- TimeSpan: The specified type member 'TotalHours' is not supported in LINQ to Entities
- How do I select all distinct strings in a list of lists of another type?
- Use a function both directly and as a lambda expression
- linq query proper way to filter
- Does the order of a IQueryable stay in the actual query in C# EF Core?
- Unable to write a Where Clause with Linq where data contains an array
- Linq to xml foreach not working
- Watin IE becomes visible when using a LINQ where
- Convert SQL Group to equivalent in Linq for Entity Framework
- Editing XML document using C#
- Recursive Hierarchy - Recursive Query using Linq
- Compare 2 List - LINQ
- How to get list of all ApplicationUsers who are in certain Role from database by LINQ expression?
- What is the effect of using AsEnumerable() on paging?
- EFCore Linq Cannot perform an aggregate function on an expression containing an aggregate or a subquery
- Query decendants in XML to Linq
- Linq result from many tables into an inherit class with nested classes
- Convert Expression<Func<TInterface, bool>> to Expression<Func<TImplementation, bool>>
- how to handle source data changes in LINQ?
- Cast a DataGridViewRow to a CustomDataGridViewRow
- using linq to select a column from a datatable
- Group By Multiple Columns
- Get image from SQL Server into datagrid with wpf C# Ado.Net Data Entity
- Displaying Custom Fields in LINQ to Entity Dynamic Select
- how to query over a list of numbers in line
- When to expect IEnumerable and when to expect IQueryable from a Linq query
- LINQ: Select distinct from a lst and append different properties into one
- How to Select a grandchild element of a element using xDocument and Linq