Shawn Weisfeld

I find when I talk to myself nobody listens. - Shawn Weisfeld
posts - 365, comments - 174, trackbacks - 34

My Links

News


Shawn Weisfeld's Facebook profile

The views expressed in this blog are mine and mine alone, not that of my employer, Microsoft, or anyone else’s. No warrantee is given for the quality of any material on this site.

Archives

Post Categories

Reflect on dll from the disk

Got a question after my reflection talk I gave to the User Group last week. The attendee wanted to load a dll from the disk and reflect on it. The assembly class has a LoadFile method that makes this easy as pie. Here is a code sample.

            //Read the dll from the disk
            Assembly assembly = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + "Microsoft.Practices.ObjectBuilder.dll");

            //Print out some information about it
            foreach (Module module in assembly.GetModules())
            {
                Console.WriteLine("{0}", module.Name);

                foreach (Type type in module.GetTypes())
                {
                    Console.WriteLine(" {0}", type.FullName);
                    foreach (MethodInfo method in type.GetMethods())
                    {
                        Console.WriteLine("  {0}", method.Name);
                    }
                }
            }

            Console.ReadKey();

Print | posted on Thursday, January 31, 2008 2:00 AM | Filed Under [ C# ]

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 4 and 3 and type the answer here:

Powered by: