InterviewSolution
Saved Bookmarks
| 1. |
What is Reflection? |
|
Answer» Reflection is a process by which a computer program can monitor and modify its own structure and behavior. It is a way to explore the structure of assemblies at run time (CLASSES, resources, methods). Reflection is the capability to find out the information about objects, metadata, and application details (assemblies) at run-time. We need to INCLUDE System.Reflection namespace to perform reflections in C#. Exmaple: PUBLIC class MyClass { public virtual int Add(int numb1, int numb2) { return numb1 + numb2; } public virtual int Subtract(int numb1, int numb2) { return numb1 - numb2; } } static void Main(string[] args) { MyClass oMyClass = new MyClass(); //Type information. Type oMyType = oMyClass.GetType(); //Method information. MethodInfo oMyMethodInfo = oMyType.GetMethod("Subtract"); Console.WriteLine("\nType information:" + oMyType.FullName); Console.WriteLine("\nMethod info:" + oMyMethodInfo.Name); Console.Read(); }Why we need Reflection We need reflection for the following purposes:
|
|