2

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

E.T.
  • 367
  • 5
  • 18

3 Answers3

5

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).

Annosz
  • 992
  • 6
  • 23
  • First of all, thanks you so much the reply, I'd just like to ask if there's a way to filter public from private methods as well using this solution – E.T. Sep 27 '19 at 09:33
  • 1
    Sadly Code Metrics do not contain information about a method's access modifier, and I haven't found a way to separate public methods from privates. Let's hope someone posts a better way to count the methods in Visual Studio. – Annosz Sep 27 '19 at 10:42
1

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

Alex S
  • 1,171
  • 1
  • 9
  • 25
0

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

NDepend

Kahbazi
  • 14,331
  • 3
  • 45
  • 76
  • 1
    It's worth noting that this is a non-free method, as NDepend only has a 14 days long trial. – Annosz Sep 30 '19 at 11:18