// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; using System.Reflection; namespace E { public class AssemblyUtil { public delegate void Process(string clznam); public static void ListAssembly(string asmnam, Process p) { Assembly asm = Assembly.LoadFile(asmnam); Type[] types = asm.GetExportedTypes(); foreach(Type t in types) { p(t.FullName); } } } public class Program { public static void Print(string clznam) { Console.WriteLine(clznam); } private static Dictionary counter = new Dictionary(); public static void CountNS(string clznam) { string ns; int ix = clznam.LastIndexOf('.'); if(ix < 0) { ns = ""; } else { ns = clznam.Substring(0, ix); } if(counter.ContainsKey(ns)) { counter[ns]++; } else { counter.Add(ns, 1); } } public static void Main(string[] args) { AssemblyUtil.ListAssembly(@"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Web.dll", Print); AssemblyUtil.ListAssembly(@"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Web.dll", CountNS); foreach(string ns in counter.Keys) { Console.WriteLine(ns + " : " + counter[ns]); } } } }