.NET中的类数?

Pet*_*sen 15 .net

.NET中的类总数是多少?下载的.NET 2.0,.NET 3.0和.NET 3.5 SP1运行时中的数字.

我们正在撰写一篇关于基于.NET的应用程序的科学论文,目前声明有超过6000个类.但我不确定这是不是正确的数字.

例如,此页面说明了程序集,名称空间,方法等的数量,但不是类的数量.

测试平台:Windows XP 64位SP2,8 GB RAM.


更新4:我们的论文已经发表!我使用9911作为课程数量(见下面的更新3).该杂志是Journal of Proteome Research,标题是:" MSQuant,一种基于质谱的定量蛋白质组学的开源平台 ".不幸的是,论文的全文不是免费提供的,只是摘要.

更新3:我认为我现在已经非常接近解决方案:用于.NET 3.5 SP1的9911公共类.在更新1上进行扩展,我已经使函数递归并对其进行了扩展,因此报告了任何子文件夹及其子文件夹的类型,类和公共类的数量.在C:\ WINDOWS\Microsoft.NET上运行此命令可提供40414类型,仅占引用文章中数字的0.2%. 完整的成绩单 - HTML源是制表符分隔的,因此可以将其导入电子表格,例如OpenOffice Calc.以下是公共课的细分:

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
Run Code Online (Sandbox Code Playgroud)

更新2:我尝试使用lextm建议的NDepend和CQL,它为.NET 2.0(在C:\ WINDOWS\Microsoft.NET\Framework\v2.0.50727中为89个DLL)提供了10%的数字:5855个类.这与系统解决方案不同(见下文).

程序:

  1. 通过http://www.ndepend.com/NDependDownload.aspx下载NDepend(NDepend_2_12_1_3122.zip)

  2. 用7-Zip解压缩

  3. 运行VisualNDepend.exe

  4. 菜单文件/选择要分析的.NET程序集/ <在C:\ WINDOWS\Microsoft.NET\Framework\v2.0.50727中选择89个DLL文件>/<全部选择> /确定.

  5. 按"创建查询"(右下角)并键入/粘贴:

    选择类型来自汇编"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 .安装","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和IsClassSystem.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和IsClassSystem.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和IsClass绘制","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绘制","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"System.Transactions","System.Web","System.Web.Mobile","System.Web.RegularExpressions","System.Web.Services","System.Windows.Forms","System.XML"WHERE IsPublic和IsClass"System.Transactions","System.Web","System.Web.Mobile","System.Web.RegularExpressions","System.Web.Services","System.Windows.Forms","System.XML"WHERE IsPublic和IsClass


更新1:根据Jon Skeet的回答,我开发了一个函数(如下所列).初步结果是5265个公共类,总共12626个类,.NET 2.0的18317个类.来自mscorlib.dll的802个公共类和来自System.dll的678个公共类.这是来自89个DLL文件,其中40个与Assembly.LoadFrom()失败.但我不确定我是在正确的地方或在正确的地方衡量的.

呼叫:

DotNetClassCount("C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727")
Run Code Online (Sandbox Code Playgroud)

功能:

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()
Run Code Online (Sandbox Code Playgroud)

Jon*_*eet 17

该页面给出了类型的数量(3.5SP1中的40513) - 区分类和结构/枚举/接口是否真的很重要?

我希望那些40K +中的绝大多数都是上课,所以你的6000数字非常保守.

给定一个程序集列表,可以很容易地计算出类的数量:

int classes = assemblies.GetTypes()
                        .Where(t => t.IsClass)
                        .Count();
Run Code Online (Sandbox Code Playgroud)

这假设您想要 所有课程 - 您实际上只对公共课程感兴趣吗?

int classes = assemblies.GetTypes()
                        .Where(t => t.IsClass && t.IsPublic)
                        .Count();
Run Code Online (Sandbox Code Playgroud)