.NET Framework's Reflection API allows you to fetch type (assembly) information at runtime programmatically. We can also achieve late binding by using .NET Reflection.
Assemblies contain modules, modules contain types, and types contain members.
At runtime, the Reflection mechanism uses the PE file to read information about the assembly.
The
Before we start using Reflection, it is necessary to understand the
Assemblies contain modules, modules contain types, and types contain members.
At runtime, the Reflection mechanism uses the PE file to read information about the assembly.
The
System.Reflection
namespace contains the classes and interfaces that provide a managed view of loaded types, methods, and fields, with the ability to dynamically create and invoke types; this process is known as Reflection in .NET framework. We will take a look at some of the commonly used classed here:Class | Description |
Assembly | Represents an assembly, which is a reusable, versionable, and self-describing building block of a Common Language Runtime application. This class contains a number of methods that allow you to load, investigate, and manipulate an assembly. |
Module | Performs Reflection on a module. This class allows you to access a given module within a multi-file assembly. |
AssemblyName | This class allows you to discover numerous details behind an assembly's identity. An assembly's identity consists of the following:
|
EventInfo | This class holds information for a given event. Use the EventInfo class to inspect events and to bind to event handlers. |
FieldInfo | This class holds information for a given field. Fields are variables defined in the class. FieldInfo provides access to the metadata for a field within a class, and provides dynamic set and get functionality for the field. The class is not loaded into memory until Invoke or get is called on the object. |
MemberInfo | The MemberInfo class is the abstract base class for classes used to obtain information about all members of a class (constructors, events, fields, methods, and properties). |
MethodInfo | This class contains information for a given method. |
ParameterInfo | This class holds information for a given parameter. |
PropertyInfo | This class holds information for a given property. |
System.Type
class.
Comments
Post a Comment