Exactly how large is the .NET (3.5) Framework Class Library?

两盒软妹~` 提交于 2019-12-03 02:51:27

These 2 blog posts address this topic:

Results are broken down by number of assemblies, namespaces, types, members, and other items.

You could use reflection to find the number of different types in the BCL but what are you hoping to accomplish with that information?

Here is an example of how to get that information:

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());
    }
}

Just note that you will need to do this for every assembly in the framework to get total numbers.

Edit: Here is a quick and dirty solution that should give you a general idea of the number of types in the 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);
    }
}

I haven't used it myself, but I think this is the sort of information that NDepend can provide to you.

It's so big that noone truly knows its size?

As far as file size goes, on my system the 2.0, 3.0 and 3.5 frameworks take up around 130MB disk space, and the 64 bit versions take roughly 93MB. But that's not counting the stuff that is core to Win7 itself.

Kevin Won

It's a bit difficult to answer without having a definition of what 'big' means -- IL (.dll) size? Source code size? Scope of functionality? Also, are you talking about the most recent redistributable of 3.5 SP1 without any of the official add-ons (that is, F# stuff, MVC, etc.) that are fully supported parts of the 'framework' but don't ship with the 3.5 redistributable?

I am not trying to be difficult... I am just saying that there is a few variables that go into how one would even determine what is to be measured, then some questions about what kind of stick is used to measure it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!