.NET(3.5)框架类库究竟有多大?

Ash*_*Ash 10 .net base-class-library

我经常读到这个框架太大了,一个开发人员无法体验它的每一部分.有一些实际数字肯定有助于把事情放在眼里.

MSDN似乎列出了所有这些,但没有实际的数字(从我能看到的),花费数小时计算它们并不是我对生产时间的看法.

  • 命名空间数
  • 课程数量
  • 结构数量
  • 接口数量

我意识到还有代表,枚举,事件等,但上述类型是最感兴趣的.

此外,基类库(BCL)中的类型数量以及整个框架类库(FCL)的大小将是有趣的.

这些信息有两种用途:

首先,要了解您实际使用的整体框架的数量以及您还需要学习多少.

其次,来自其他平台(和非技术人员)的许多程序员经常会惊讶于程序员可以将大部分时间花在".NET Framework"中.有一些数字肯定有助于解释为什么这不是狭隘的技能/经验的迹象.

[更新]

使用安德鲁的代码(在我的.NET 3.5 SP1系统上),我得到:

Classes: 12688
Value types: 4438
Interfaces: 1296

Ahm*_*eed 6

这2篇博客文章涉及这个主题:

结果按程序集,名称空间,类型,成员和其他项目的数量进行细分.


And*_*are 5

你可以使用反射来查找BCL中不同类型的数量,但是你希望用这些信息完成什么?

以下是如何获取该信息的示例:

using System;
using System.Linq;
using System.Reflection;

class Example
{
    static void Main()
    {
        Assembly mscorlib = typeof(String).Assembly;

        // Number of classes
        Console.WriteLine(mscorlib.GetTypes().Where(t => t.IsClass).Count());
        // Number of value types (structs and enums)
        Console.WriteLine(mscorlib.GetTypes().Where(t => t.IsValueType).Count());
        // Number of interfaces
        Console.WriteLine(mscorlib.GetTypes().Where(t => t.IsInterface).Count());
    }
}
Run Code Online (Sandbox Code Playgroud)

请注意,您需要为框架中的每个程序集执行此操作以获取总数.

编辑:这是一个快速而肮脏的解决方案,可以让您大致了解BCL中的类型数量:

using System;
using System.Linq;
using System.Reflection;
using System.IO;
using System.Runtime.InteropServices;

class Example
{
    static void Main()
    {
        // Get all DLLs in the current runtime directory
        var assemblies = Directory.GetFiles(
            RuntimeEnvironment.GetRuntimeDirectory())
            .Where(f => f.EndsWith(".dll"));

        Int32 classes = 0;
        Int32 valueTypes = 0;
        Int32 interfaces = 0;

        foreach (String name in assemblies)
        {
            // We need to catch BadImageFormatException
            // because not all DLLs in the runtime directory
            // are CLR assemblies.
            try
            {
                var types = Assembly.LoadFile(name).GetTypes();

                classes += types.Where(t => t.IsClass).Count();
                valueTypes += types.Where(t => t.IsValueType).Count();
                interfaces += types.Where(t => t.IsInterface).Count();
            }
            catch (BadImageFormatException) { }
        }

        Console.WriteLine("Classes: {0}", classes);
        Console.WriteLine("Value types: {0}", valueTypes);
        Console.WriteLine("Interfaces: {0}", interfaces);
    }
}
Run Code Online (Sandbox Code Playgroud)