E.T.
E.T.

Reputation: 367

How to count all methods on a visual studio solution

Is there a way to easily access on visual studio the method total count on an entire NetCore solution?

Upvotes: 2

Views: 7141

Answers (3)

Alex S
Alex S

Reputation: 1221

Yes, here is an alternative solution to the already proposed ones.

Solution: Using C# interactive window to get method count through reflection.

Step 1

Open C# interactive window in Visual Studio. Example: https://stackoverflow.com/a/11135787

Step 2

Get full path to your DLL or folder with DLLs.

Step 3

Paste reflection code into C# interactive window.

Step 4

Improve / customize reflection code to suite your needs. Search Stackoverflow for existing reflection solutions.

Simple code example:

Console.WriteLine(Assembly.LoadFrom(@"<single DLL path here>").GetTypes().Select(x => x.GetMethods().Count()).Sum());

enter image description here

Upvotes: 1

Kahbazi
Kahbazi

Reputation: 15015

You can install NDepend extension on visual studio. It shows the total number of methods on its dashboard.

NDepend

Upvotes: 0

Annosz
Annosz

Reputation: 1032

In Visual Studio you can use the Analyze > Calculate Code Metrics > For Solution menu to calculate code metrics for every function. This is good for you, because in the result window you will get a rundown for every function that is in your code.

However, this result is not really useful, because it contains getters and setters as separate functions. To solve this, I right clicked on the main node (or on any node you want to explore) and selected Open Selection in Microsoft Excel. Here I set up the following filter on the Member column:

Setting up Excel filter for methods

The first row makes sure to only include functions, the second ensures that we do not count the getters or setters. This way our filtered table will contain as many rows as many user defined functions are there in our solution (you can select a whole column and in the down-right part of the window it shows the count of rows that contain something).

Upvotes: 6

Related Questions