Search code examples
c#vb.netclassvb6

How to calculate number of classes in a project


We are dealing with VB6 and .NET project and need to calculate the number of classes.

For vb6 we sum up the total number of standard and class modules which gives us the total number of classes in project.

For .NET we calculate the total number of code behind files, and in standalone .vb or .cs files we calculate the number of classes defined inside. This total is considered as final count.

Is this correct? or in .NET is the standalone .vb or .cs file supposed to be considered as 1 class rather than counting the classes inside this file??


Solution

  • For .NET we calculate the total number of code behind files, and in standalone .vb or .cs files we calculate the number of classes defined inside. This total is considered as final count.

    Is this correct? or in .NET is the standalone .vb or .cs file supposed to be considered as 1 class rather than counting the classes inside this file??

    No you cannot be sure that counting files can reveal total number of classes.

    Reason
    1. There can be more than one class in a .cs or .vb file. Although it is a good practice to have only one class in a code file but .Net does not restrict you to have more than one class in a file.
    2. A class can exist in multiple files through the use of partial keyword in C# and Partial keyword in VB.Net.

    Hence always count the distinct names of classes in .Net.