Thursday, February 01, 2007

"Creating Even More Exceptional Exceptions" from Jeff Atwood

Today i found a very nice blog entry, only sickness its vb.net ;-) (sorry jeff)

to original can be found here

thanks jeff for the nice idea.

here the same in C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Reflection;
using System.Configuration;

namespace ExceptionalExceptions
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Started ...");
ReflectionSearch(".*exception$");

Console.ReadLine();
}

private static void ReflectionSearch(string strPattern)
{
Assembly a;
ArrayList al = new ArrayList();
SortedList sl = new SortedList();

foreach(string strAssemblyName in DefaultAssemblyList())
{
a = Assembly.Load(strAssemblyName);
foreach(Module m in a.GetModules())
{
foreach(Type t in m.GetTypes())
{
al.Add(t);
string full = t.FullName;
if(Regex.IsMatch(full, strPattern, RegexOptions.IgnoreCase))
{
if(!sl.ContainsKey(full))
sl.Add(full, null);
}
}
}
}

foreach(DictionaryEntry de in sl)
{
Console.WriteLine(de.Key);
}
Console.WriteLine(sl.Count.ToString() + " matches for " + strPattern);



}

private static ArrayList DefaultAssemblyList()
{
ArrayList result = new ArrayList();

result.Add("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089");
result.Add("System.Data.SqlXml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089");
result.Add("System.Deployment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A");
result.Add("System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A");
result.Add("System.DirectoryServices.Protocols, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A");
result.Add("System.Runtime.Serialization.Formatters.Soap, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A");
result.Add("System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089");
result.Add("System.Web.RegularExpressions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A");
result.Add("System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A");
result.Add("System.Runtime.Remoting, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089");
result.Add("System.Configuration.Install, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A");
result.Add("System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A");
result.Add("System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089");
result.Add("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089");
result.Add("System.EnterpriseServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A");
result.Add("System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A");
result.Add("System.Web.Services, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A");
result.Add("System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089");
result.Add("System.Web.Mobile, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A");

return result;
}
}
}

1 comment:

Paulstrious said...

My german is non-existent. Hope this is a comment area...

Updated the code to 3.5 framework back at the other site.

Shared Cache - .Net Caching made easy

All information about Shared Cache is available here: http://www.sharedcache.com/. Its free and easy to use, we provide all sources at codeplex.

Facebook Badge