Types
Later on I will go into this in greater
detail, but this will be just a quick overview here.
You probably know that when you create a
class, you are essentially creating a type. A lot of people underestimate the
power of a type, you may have used GetType once in a while, but you may
not know the underlying power of it. The Type class contains a heck of
a lot of information about an type that you can access and then can lead on to
some pretty interesting abilities.
System.Reflection
The System.Reflection namespace
contains all of the tools needed to provide a view (in code) of any assembly
in .NET. If you take a look at the Object Browser in VS.NET, that is the
equivalent of using System.Reflection to find out about all of that
information. Intellisense in VS.NET is also like using System.Reflection
and Lutz Roeder's .NET Reflector
uses System.Reflection to browse an assembly.
But why would you use System.Reflection?
Let's say that you were given an assembly and
you have no idea what it contains or does, you could use reflection to find
out what's in it and how it works.
Or, if you were developing a dynamic documentation system, then you could just
place an assembly in the /bin directory and develop an application that used
reflection to dynamically generate information and documentation about the
assembly (much like the Comment Web Pages with XML Code Comments in VS.NET).
MethodInfo
MethodInfo is a class within
System.Reflection that allows you to get information about specific
methods (which I will be using in this article). For example, you can give it
a method and you can get all sorts of properties and methods back which you
can use to examine that method.