Number of classes in the .NET Framework

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

I have it in my head that I saw a marketing document from Microsoft with the
total number of classes and methods in the .NET Framework. Something like
70,000 methods? I don't need precise numbers, but a rough estimate of the
number of classes and methods would be useful ....

Thanks in advance.

Mark
 
Thanks for your detailed reply. Perhaps .... out of curiosity? While I
don't see the number being included in the next release of trivial pursuit,
the numbers would be intellectually interesting when describing some of the
complexities of the .NET Framework to management or others ...

Do you have the answer?

Mark
 
Theres an exanple somewhere on the web (might be in the quickstart) that
demonstrates reflection by cycling through the framework classes. If you
can find it - you should be able to add a line or two to acquire a count of
the classes.

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP
 
You could write a fairly trivial program that loaded all the .NET
assemblies, and used reflection to count up the classes and methods. I'm
too busy, or I'd do it myself for the fun of it, but it would be a good
way to introduce yourself to reflection if you've never played with it
before, and in itself would be a good demonstration of the
sophistication of the framework.

-Jason
 
Great idea. I looked at the quickstart example John refered to in this
thread. I pasted it below. The only problem I'm seeing with reflection is
that you need to know the names of all the dlls. OR, is there a list of
these someplace?

Thanks again.

Mark
 
Drat - forgot to indluce the sample code I promised found at
http://samples.gotdotnet.com/quickstart/howto/ (click on reflection on the
left):

// don't forget your using statements
using System;
using System.Reflection;
// ...

// Getting an Assembly, method 1. Get the mscorlib assembly
// Note that other types such as String, or Int32 would have worked just as
well,
// since they reside in the same assembly
Assembly a = typeof(Object).Module.Assembly;

// Getting an Assembly, method 2. Load a particular assembly, using a
reference to a
// module that is within that assembly. Note that this requires a compiled
module for
// the reference, and when running in an aspx page, will require a fully
qualifed path
// to the file, to ensure it is correctly identified
Assembly b = Assembly.LoadFrom ("GetTypes.exe");

// note that either of the above methods is viable, depending on the
information
// you have. Since we know the name of the file which houses all of the base
system
// objects, we could do the following to replace the first example, just as
effectively
// (the absolute path may change on your machine)
// Assembly a = Assembly.LoadFrom
// ("c:/winserv/microsoft.net/framework/v1.0.2230/mscorlib.dll");
 
Yeah, I was afraid you were going to ask that. You can just figure out
the list manually by using gacutil, or looking at the dlls in the
framework install directory. That's no fun of course, and what you'd
really like to be able to do is get at that programatically, which
appears to be possible, but undocumented, and certainly is progressing a
bit beyond the trivial:

http://support.microsoft.com/default.aspx?scid=kb;en-us;317540

I found that link here, which is a nice overview of the GAC:

http://www.codeproject.com/dotnet/DemystifyGAC.asp

-Jason
 
Cool - I went through all the System namespaces and found:

Class count: 4760
Method count: 119656

The code is below. Anything I'm messing up here? Thanks again.

//***** To run this code, throw it in the button click event on a WinForm
and put a textbox on the form titled "txtOutput" *****

int intClassCount = 0;
int intMethodCount = 0;
StringBuilder sb = new StringBuilder();

string[] Ass = new string[21];
Ass[0] = "System.Configuration.Install.dll";
Ass[1] = "System.Data.dll";
Ass[2] = "System.Data.OracleClient.dll";
Ass[3] = "System.Design.dll";
Ass[4] = "System.DirectoryServices.dll";
Ass[5] = "System.dll";
Ass[6] = "System.Drawing.Design.dll";
Ass[7] = "System.EnterpriseServices.dll";
//System.EnterpriseServices.Thunk.dll
//Ass[8] = "System.EnterpriseServices.Thunk.dll"; //It coudn't find this
one.
Ass[8] = string.Empty;
Ass[9] = "System.Management.dll";
Ass[10] = "System.Messaging.dll";
Ass[11] = "System.Runtime.Remoting.dll";
Ass[12] = "System.Runtime.Serialization.Formatters.Soap.dll";
Ass[13] = "System.Security.dll";
Ass[14] = "System.ServiceProcess.dll";
Ass[15] = "System.Web.dll";
Ass[16] = "System.Web.Mobile.dll";
Ass[17] = "System.Web.RegularExpressions.dll";
Ass[18] = "System.Web.Services.dll";
Ass[19] = "System.Windows.Forms.dll";
Ass[20] = "System.XML.dll";


for(int intAssemblyCount = 0; intAssemblyCount < Ass.Length;
intAssemblyCount ++)
{
if (Ass[intAssemblyCount] != string.Empty)
{
Assembly a = Assembly.LoadFrom
(@"C:\WINNT\Microsoft.NET\Framework\v1.1.4322\" +
Ass[intAssemblyCount]);

//int intPropertyCount = 0;

Module[] mod = a.GetModules();
sb.Append(Environment.NewLine +"Assembly FullName: " + a.FullName);

for (int i = 0; i < mod.Length; i++)
{
Module m = mod;
sb.Append(Environment.NewLine + "FullyQualifiedName: " +
m.FullyQualifiedName);
sb.Append(Environment.NewLine + "Name: " + m.Name);
}

Type [] types = a.GetTypes ();
foreach (Type t in types)
{
if ( t.IsClass)
{
intClassCount++;
sb.Append(Environment.NewLine + "Class.Name: " + t.Name);

MethodInfo[] methods = t.GetMethods();

for (int i = 0; i < methods.Length; i++)
{
MethodInfo mi = methods;
//sb.Append(Environment.NewLine + " Method Name: " + mi.Name);
intMethodCount++;
}
}
}
}
}

sb.Append(Environment.NewLine + "Class count: " +
intClassCount.ToString());
sb.Append(Environment.NewLine + "Method count: " +
intMethodCount.ToString());

txtOutput.Text = sb.ToString();
 
Back
Top