Note that there are some explanatory texts on larger screens.

plurals
  1. PONumber of classes in .NET?
    primarykey
    data
    text
    <p>What is the total number of classes in .NET? The number that is in the downloaded runtime for .NET 2.0, .NET 3.0 and .NET 3.5 SP1.</p> <p>We are writing a scientific paper about an application that is based on .NET and currently state that there are more than 6000 classes. But I am not sure if this is the correct number.</p> <p>For instance <a href="http://codebetter.com/blogs/patricksmacchia/archive/2008/08/13/net-3-5-sp1-changes-overview.aspx" rel="nofollow noreferrer">this page</a> states the number of assemblies, namespaces, methods, etc., but not the number of classes.</p> <p>Test platform: Windows XP 64 bit SP2, 8 GB RAM.</p> <hr> <p><strong>Update 4</strong>: Our paper has been published! I used 9911 for the number of classes (see update 3 below). The journal is <a href="http://en.wikipedia.org/wiki/Journal_of_Proteome_Research" rel="nofollow noreferrer">Journal of Proteome Research</a> and the title is: "<a href="http://pubs.acs.org/doi/abs/10.1021/pr900721e" rel="nofollow noreferrer">MSQuant, an Open Source Platform for Mass Spectrometry-Based Quantitative Proteomics</a>". Unfortunately the full text of the paper is not freely available, only the abstract.</p> <p><strong>Update 3</strong>: I think I have come very close to a solution now: 9911 public classes for .NET 3.5 SP1. Extending on update 1, I have made the function recursive and extended it so the number of types, classes and public classes are reported for any sub-folder and its subfolders. Running this on C:\WINDOWS\Microsoft.NET gives 40414 types, only 0.2 % from the number in the <a href="http://codebetter.com/blogs/patricksmacchia/archive/2008/08/13/net-3-5-sp1-changes-overview.aspx" rel="nofollow noreferrer">referenced article</a>. <a href="http://pmortensen.eu/1/until2039-12-31/SO/dorNetAssembliesSummary.html" rel="nofollow noreferrer">Full transcript</a> - HTML source is tab separated so it can be imported into a spreadsheet, e.g. <a href="http://en.wikipedia.org/wiki/OpenOffice.org_Calc" rel="nofollow noreferrer">OpenOffice Calc</a>. Here is a break-down for public classes:</p> <pre><code>Framework: Total: 6025 v1.1.4322 0 v2.0.50727 5265 v3.0 641 v3.5 119 Framework64: Total: 3886 v2.0.50727 3126 v3.0 641 v3.5 119 </code></pre> <p><strong>Update 2</strong>: I tried using NDepend and CQL suggested by lextm and it gave a 10% higher number for .NET 2.0 (89 DLLs in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727): 5855 classes. This was on a different system than for the programmatic solution (see below).</p> <p>Procedure:</p> <ol> <li><p>Download NDepend (NDepend_2_12_1_3122.zip), via <a href="http://www.ndepend.com/NDependDownload.aspx" rel="nofollow noreferrer">http://www.ndepend.com/NDependDownload.aspx</a></p></li> <li><p>Unzip with 7-Zip</p></li> <li><p>Run VisualNDepend.exe</p></li> <li><p>Menu File/Select .NET Assemblies to Analyze/ &lt;Selected the 89 DLL files in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727&gt;/ &lt;Selected all&gt;/ OK.</p></li> <li><p>Press "Create Query" (lower right) and type/paste:</p> <p>SELECT TYPES FROM ASSEMBLIES "Accessibility", "cscompmgd", "CustomMarshalers", "IEExecRemote", "IEHost", "IIEHost", "ISymWrapper", "Microsoft.Build.Engine", "Microsoft.Build.Framework", "Microsoft.Build.Tasks", "Microsoft.Build.Utilities", "Microsoft.JScript", "Microsoft.VisualBasic", "Microsoft.VisualBasic.Compatibility", "Microsoft.VisualBasic.Compatibility.Data", "Microsoft.VisualBasic.Vsa", "Microsoft.VisualC", "Microsoft.Vsa", "Microsoft.Vsa.Vb.CodeDOMProcessor", "Microsoft_VsaVb", "mscorlib", "sysglobl", "System", "System.configuration", "System.Configuration.Install", "System.Data", "System.Data.OracleClient", "System.Data.SqlXml", "System.Deployment", "System.Design", "System.DirectoryServices", "System.DirectoryServices.Protocols", "System.Drawing", "System.Drawing.Design", "System.EnterpriseServices", "System.Management", "System.Messaging", "System.Runtime.Remoting", "System.Runtime.Serialization.Formatters.Soap", "System.Security", "System.ServiceProcess", "System.Transactions", "System.Web", "System.Web.Mobile", "System.Web.RegularExpressions", "System.Web.Services", "System.Windows.Forms", "System.XML" WHERE IsPublic AND IsClass</p></li> </ol> <hr> <p><strong>Update 1</strong>: based on Jon Skeet's answer I have developed a function (listed below). The preliminary result is 5265 public classes, 12626 classes in total, 18317 types for .NET 2.0. 802 public classes from mscorlib.dll and 678 public classes from System.dll. This is from 89 DLL files of which 40 fails with Assembly.LoadFrom(). But I am not sure I measure the right thing or in the right place.</p> <p>Call:</p> <pre><code>DotNetClassCount("C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727") </code></pre> <p>Function:</p> <pre><code>Imports System.Reflection 'For Assembly Imports System.IO 'For Path Private Function DotNetClassCount(ByRef aBaseDirectory As String) _ As Integer Dim classCount As Integer = 0 Dim failCount As Integer = 0 'For statistics only. Dim folderItems As String() = Directory.GetFiles(aBaseDirectory) Dim someFolderItem As String For Each someFolderItem In folderItems Dim fileName As String = Path.GetFileName(someFolderItem) If Path.GetExtension(fileName) = ".dll" Then Try Dim asm3 As Assembly = _ Assembly.LoadFrom(someFolderItem) Dim types As System.Type() = asm3.GetTypes() Dim DLLclassCount As Integer = 0 Dim someType As System.Type For Each someType In types If someType.IsClass AndAlso someType.IsPublic Then DLLclassCount += 1 End If Next classCount += DLLclassCount Catch ex As Exception 'Fail silently... failCount += 1 End Try End If Next Return classCount End Function 'DotNetClassCount() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload