Reflection is one of the features provided by the .Net framework to get information about objects, assemblies and their metadata at runtime. Its provides us with the ability to read, write, invoke methods from the assemblies on the fly.
The Asssembly class
This class provides loads of methods that can be used to load assemblies dynamically, get information about the members of the assemby that is being loaded, etc.
Assembly myAssembly = Assembly.FromFile("..\foo.dll"); //Will load the assembly named foo.dll found in the specified path
We can get the member informations using the methods like GetTypes()
Type[] myFooTypes = myAssembly.GetType(); //Gets all the types of foo's assembly
Before getting any information about any of the assembly, we need to first get the type of the object. Once we get the type, we can get the members using the GetMember() or GetMembers() method. One can even get the fields using the GetField() or GetFields() methods, properties using the GetProperty() or GetProperties() method. The difference between the singular and the plural methods is that the later will return a list of such type. For example, the GetMethods() will return a method list to the lvalue.
Gettings methods
MethodInfos aFoosMethods = myFooTypes[0].GetMethods(); //Will return a list of available methods in the class represented by myFooTypes[0]
The second overload of the method, GetMethods(), takes an addition parameter called the BindingsInfo. This can be used to tell the csc about the method type that you are looking for — whether it is private or public or static, etc.
MethodInfo aFoosMethod = myFooTypes[0].GetMethod(BindingsInfo.NonPublic | BindingsInfo.Instance); //NonPublic -- private, Instance -- Specifies that instance members are to be included in the search
If you want to get information about a particular method then use, GetMethod(<method_name_as_string>);
Gettings Fields
FieldsInfo aFooField = myFooTypes[0].GetFields(); //You can also pass BindingsInfo to this method as parameters
For a specific field GetField(<name_of_the_field_as_string>);
Getting Properties
PropertyInfo aFooProperty = myFooTypes[0].GetProperties();
For a specific property use GetProperty(<name_of_the_property_as_string>);
Getting the pramters information
To get the parameter information use, ParameterInfo object
ParameterInfo[] aFooBarParameters = aFoosMethods[0].GetParameters(); //Will get the parameters of the methods Foo.Bar()
Setting values in the runtime
FieldInfo aFooField = myFooTypes[0].GetField("number", BindingInfo.NonPublic | BindingInfo.Instance).SetValue(this, 100); //this represents the object whoes member should be altered (number is an instance of this)
Uses of Reflections
Reflections are used in many fields. I found the above to be some of the interesting ones. I use it mainly for tracing. If you find anything else as interesting about reflections, comment on it.
* Reflections may slowdown the performance of your application. So be choosy on when to use reflections.
Update
This is how you create objects of private classes of a assembly in another assembly
Tags: C#, General Programming, Tips 'n' Tricks

Nice and precise post. Keep it up.
Thanks. I suggest you write a post explaining more about using Database in c#. It will be nice if we have some code snippets in the posts.
Also this is the namespace which provides the “Pointer” class – a wrapper class for using pointers in C# (i.e in case u wanted to use unmanaged memory pointers).Check out the “Box” Method for the Pointer class.
Indeed a good intro to reflection …keep it up
Well i remember using it once to get the name of the current executing method(seriously, where else do you get spoon fed like this !!).Goes something like this..
string methodName = MethodBase.GetCurrentMethod().Name;