using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
namespace AssemblyLoadTest
{
class Program
{
static void Main(string[] args)
{
LoadAssemblies();
WriteMethodNameCount();
}
private static void LoadAssemblies()
{
String[] assemblies ={
"System, PublicKeyToken={0}",
"System.Data, PublicKeyToken={0}",
"System.Data.OracleClient, PublicKeyToken={0}",
"System.Data.SqlXml, PublicKeyToken={0}",
"System.Runtime.Remoting, PublicKeyToken={0}",
"System.Windows.Forms, PublicKeyToken={0}",
"System.Transactions, PublicKeyToken={0}",
"System.Xml, PublicKeyToken={0}",
"System.Configuration, PublicKeyToken={1}",
"System.Configuration.Install, PublicKeyToken={1}",
"System.Deployment, PublicKeyToken={1}",
"System.Design, PublicKeyToken={1}",
"System.DirectoryServices, PublicKeyToken={1}",
"System.DirectoryServices.Protocols, PublicKeyToken={1}",
"System.Drawing, PublicKeyToken={1}",
"System.Drawing.Design, PublicKeyToken={1}",
"System.EnterpriseServices, PublicKeyToken={1}",
"System.Management, PublicKeyToken={1}",
"System.Messaging, PublicKeyToken={1}",
"System.Runtime.Serialization.Formatters.Soap, PublicKeyToken={1}",
"System.Security, PublicKeyToken={1}",
"System.ServiceProcess, PublicKeyToken={1}",
"System.Web, PublicKeyToken={1}",
"System.Web.Mobile, PublicKeyToken={1}",
"System.Web.RegularExpressions, PublicKeyToken={1}",
"System.Web.Services, PublicKeyToken={1}",
};
String EcmaPublicKeyToken = "b77a5c561934e089";
String MSPublicKeyToken = "b03f5f7f11d50a3a";
foreach (String a in assemblies)
{
String AssemblyIdentity =
String.Format(a, EcmaPublicKeyToken, MSPublicKeyToken) +
", Culture=neutral, Version=2.0.0.0"
Assembly.Load(AssemblyIdentity);
}
}
///<summary>
///
///</summary>
private static void WriteMethodNameCount()
{
Int32 totalMethods = 0;
List<String> methodTree = new List<string>();
foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (Type t in a.GetExportedTypes())
{
if (!t.IsClass || !t.IsPublic)
{
continue;
}
const BindingFlags bf =
BindingFlags.Public |
BindingFlags.Instance | BindingFlags.Static |
BindingFlags.DeclaredOnly;
List<String> typeHierarchy = new List<String>();
MethodInfo[] methodes = t.GetMethods(bf);
List<String> d = new List<String>();
foreach (MethodInfo m in methodes)
{
if (!d.Contains(m.Name))
{
d.Add(m.Name);
typeHierarchy.Add(m.Name);
}
}
foreach (String s in typeHierarchy)
{
totalMethods++;
methodTree.Add(s);
}
}
}
methodTree.Sort();
Regex r = new Regex("^[A-Z][a-z]*");
Dictionary<String, Int32> nameCount = new Dictionary<string, int>();
System.IO.StreamWriter sw = new System.IO.StreamWriter(@"D:\MethodNameCount.txt", false);
foreach (String s in methodTree)
{
Match m = r.Match(s);
if (m.Success)
{
if (nameCount.ContainsKey(m.Value))
{
nameCount[m.Value] += 1;
}
else
{
nameCount.Add(m.Value, 1);
}
}
}
sw.WriteLine("全部で {0} 個のメソッドが存在します。", totalMethods);
sw.WriteLine("全部で {0} 種類のメソッドが存在します。", nameCount.Count);
foreach (KeyValuePair<String, Int32> kvp in nameCount)
{
sw.WriteLine(String.Format("{0},{1}", kvp.Key, kvp.Value));
}
sw.Close();
}
}
}