Introduction to reflection
Reflection is used to dynamically create an instance of a type, bind the type to an existing object, or get the type from an existing object and invoke its methods or access its fields and properties. If you are using attributes in your code, reflection enables you to access them.
Using the type of (className)
We can use the type of (className) function to get the information of all the methods, members and so on that is a part of the specific class. An example can be seen in the following.

Figure 1. Program.cs
The preceding code returns the following output.

Figure 2. Output
We can also get the information regarding all the properties of a specific class as in the following
If we include this in the preceding code then the output would be

Figure 3. Output2
Using GetType()
We can also get an assembly inspected by using the GetType method of the System. Reflection class. The code for that would be as in the following,

Figure 4. System reflection class
As we can see, there is not much difference between the type of and GetType methods. What is the functional difference between the two? Let's figure it out. typeOf is a C# keyword used when you have the name of the class. It is calculated at compile time and thus cannot be used on an instance that is created at runtime. GetType is a method of the object class that can be used on an instance.
Early binding vs late binding
- Performance will be good in Early binding.
- The application will run faster in Early binding since no boxing or unboxing is done here, but in late binding, we need type conversion as it will be decoded at run time.
- Easier to write the code in Early binding, since the intelligence will be automatically populated.
- Less chance of errors in early binding, since the syntax is checked that flags an error at compile time itself but for late binding there are chances of run time exceptions.
- Late binding would support all kinds of versions due to handing at run time.
- Minimal impact of code in future enhancements, if late binding is used.
Late binding using reflection
Late bindings can be done by using reflection. For example, in some applications, we don't know which assembly to load during compile time, so we ask the user to enter the assembly name and type during run time and the application can load the assembly. For this purpose, the System.Reflection.Assembly type offers three static methods that allow you to explicitly load an assembly, Load, LoadFrom, and LoadWithPartialName. These methods are something similar to the LoadLibrary Win32 API. Our System. Reflection namespace will work with assemblies and metadata.
In late binding, the compiler does not know what kind of object or actual type of an object or which methods/properties an object contains so it binds the compile-time checking that was handled by the run-time. The most popular examples of late binding are the use of the dynamic keyword and the use of reflection. The dynamic was introduced in C# 4.0 and introduced to achieve the dynamic static object that the compile-time detection but at runtime it detects the object actually type depending on the right-hand object type and converts it to a strong type.
Please see the following example of using Late Binding in C# by Reflection.

Figure 5. Example of late binding
You would need to change the path of the DLL as in your system. As you see from the preceding code the GetType() method/information is invoked during runtime.
Advantages of using late binding
- Late binding is very useful in reading the metadata information of an assembly or when an actual type is not known.
- It is also useful when an actual type is not known. Late binding is more certain to be version-independent since everything is decided at run time.
- Please find the code attached for more reference and a better understanding.


Asfend YarPosted Feb 29, 2016, 9:19 AM EST
good info
Asfend YarPosted Feb 29, 2016, 9:19 AM EST
nice
Sr KarthigaPosted Feb 26, 2016, 4:35 AM EST
good one
Sr KarthigaPosted Feb 26, 2016, 4:35 AM EST
nice explanation
Akash MalhotraPosted Sep 3, 2015, 11:15 AM EDT
Nice article
pooja guptaPosted Jul 19, 2015, 8:41 AM EDT
it really helped! nice
Lalit RaghavPosted Jun 21, 2015, 11:50 PM EDT
very thanks sir
Jaipal ReddyPosted Jun 21, 2015, 8:48 PM EDT
Nice one vipul
Vipul MalhotraPosted Jun 17, 2015, 6:36 AM EDT
Thanks
Rahul Kumar SaxenaTOP 100Posted Jun 14, 2015, 10:34 PM EDT
Good Show...
Santhakumar MunuswamyPosted Jun 12, 2015, 10:29 AM EDT
Thanks for nice article :)
Amol SarkatePosted Jun 12, 2015, 6:15 AM EDT
nice
Afzaal Ahmad ZeeshanTOP 100Posted Jun 12, 2015, 4:59 AM EDT
Good article, the dynamic keyword is also more exposed to the run-time exceptions if a member is not found. Also, Reflection can raise exceptions too if a member or similar type is not found. You should include this in the article too. :)
NitinPosted Jun 12, 2015, 3:59 AM EDT
nice
Vipul MalhotraPosted Jun 12, 2015, 3:41 AM EDT
Thanks Pankaj
Pankaj Kumar ChoudharyTOP 100Posted Jun 12, 2015, 3:30 AM EDT
Nice Start Vipul...........