Reflection

What is Reflection?
The process of obtaining information about assemblies and the types defined within them, and creating, invoking, and accessing type instances at run time.
Reflection provides objects that describe assemblies, modules and types. You can use reflection 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.
Reflection provides infrastructure used by language compilers to implement implicit late binding.
Reflection allows known data types to be inspected at runtime. Reflection allows the enumeration of data types in a given assembly, and the members of a given class or value type can be discovered. This is true regardless of whether the type was known or referenced at compile time. This makes reflection a useful feature for development and code management tools.
When Reflection is useful?
Reflection is useful in the following situations:
· When you have to access attributes in your program's metadata.
· For examining and instantiating types in an assembly.
· For building new types at runtime. Use classes in System.Reflection.Emit.
· For performing late binding, accessing methods on types created at run time.
What is late binding?
Binding is the process of locating the declaration that corresponds to a uniquely specified type. When this process occurs at run time rather than at compile time, it is called late binding.
What is Custom Binding?
The common language runtime supports multiple programming languages, and the binding rules of these languages differ. In the early-bound case, code generators can completely control this binding. However, in late binding through reflection, binding must be controlled by customized binding. The Binder class provides custom control of member selection and invocation.
Using custom binding, you can load an assembly at run time, obtain information about types in that assembly, specify the type that you want, and then invoke methods or access fields or properties on that type. This technique is useful if you do not know an object's type at compile time, such as when the object type is dependent on user input.

Which class has significant importance for reflection?

The System.Type class is central to reflection. The common language runtime creates the Type for a loaded type when reflection requests it. You can use a Type object's methods, fields, properties, and nested classes to find out everything about that type.

How do you get Type objects from assemblies that have not been loaded ?

Use Assembly.GetType or Assembly.GetTypes to obtain Type objects from assemblies that have not been loaded, passing in the name of the type or types you want.

How do you get to Type objects from an assembly that is already loaded?

Use Type.GetType to get the Type objects from an assembly that is already loadedUse Type..::.GetType to get the Type objects from an assembly that is already loaded.

How do you obtain module Type objects ?

Use Module.GetType and Module.GetTypes to obtain module Type objects.

Which property is used to determine whether the type is generic?

Use the IsGenericType property to determine whether the type is generic, and use the IsGenericTypeDefinition property to determine whether the type is a generic type definition.

Which name space contain the classes that are used to enables you to build types at run time?

System.Reflection.Emit

What is the use of System.Reflection namespace?

The System.Reflection namespace contains types that retrieve information about assemblies, modules, members, parameters, and other entities in managed code by examining their metadata. These types also can be used to manipulate instances of loaded types, for example to hook up events or to invoke methods.