Microsoft .Net Framework Public Classes Data Dump
Tuesday, December 8th, 2009I’ve wrapped up work on v0.4 of the Jsoq Console, and the insanely strenuous release cycle for v0.1 of WhatDidIJustEat.com so I’m starting another side project tonight.
Ever been working with a programming language you’re not 100% familiar with and find yourself wondering:
Is this function a built-in function or in some included library?
What assembly is this class in again?
Can I name my class XXXX without conflicting with another class?
I’ve had these questions recently and found myself annoyed and frustrated to no end (PHP, I’m looking at you) so I’ve decided to build a system to keep track of this stuff for me :D.
The first thing on my list (because it was the easiest) was to do a data dump of all the public classes in the .Net Framework, including the ones in my GAC, and store some metadata for each one in a database table. I’ve just finished this step and thought that this data might be useful, so I’m posting it here.
Currently the fields included in the data dump are:
[namespace] = The namespace that the class exists in (ex: System.Collections.Generic)
[class_name] = The name of the class (ex: StringBuilder)
[assembly_fullname] = The display name of the assembly (ex: mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
[assembly_file] = The full file path to the assembly (ex: C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll)
[framework_name] = The framework that uses this class, for this dump they will all be 'Microsoft .Net'
[framework_version] = The framework version that uses this class (ex: v.2.0.50727)
The .sql file takes about 18 seconds to run to completion on my AMD Athlon X2 2.53ghz machine with 4gb of RAM.
If you’re curious about how I generated the .sql file, below is the code I used to find all the classes. It’s not pretty but then again it was just meant to get the data into the database. Just paste the code into a new console app and run it in a command window like so:
[application_name].exe > c:\classes.sql
Or, you can download the .sql file I’ve generated (it will also create the table you need to store the data).
static void Main(string[] args)
{
var dictionary = new Dictionary(){
{ "v2.0.50727", @"C:\Windows\Microsoft.NET\Framework\v2.0.50727" },
{ "v3.0", @"C:\Windows\Microsoft.NET\Framework\v3.0" },
{ "v3.5", @"C:\Windows\Microsoft.NET\Framework\v3.5" },
{ "v???", @"c:\windows\assembly\gac" }
};
var types = new List();
foreach (var pair in dictionary)
{
var path = pair.Value;
var assemblies = Directory.GetFiles(path, "*.dll", SearchOption.AllDirectories);
foreach (string file in assemblies)
{
try
{
Assembly asm = Assembly.LoadFile(file);
foreach (Type t in asm.GetTypes())
{
if (t.IsPublic)
{
Console.WriteLine(String.Format(
"INSERT INTO Classes (" +
"[namespace], " +
"class_name, " +
"assembly_fullname, " +
"assembly_file, " +
"framework_name, " +
"framework_version" +
") " +
"VALUES (" +
"'{0}', " +
"'{1}', " +
"'{2}', " +
"'{3}', " +
"'Microsoft .Net', " +
"'{4}'" +
")",
String.IsNullOrEmpty(t.Namespace) ?
"GLOBAL" :
t.Namespace,
t.Name
.Replace("`1", "")
.Replace("`2", "")
.Replace("`3", ""),
t.Assembly.FullName,
t.Assembly.Location,
pair.Key == "v???" ?
t.Assembly.GetName().Version.ToString() :
pair.Key
));
}
}
}
catch { }
}
}
}
If you found this useful, let me know in the comments!