Sunday, August 12, 2007

Reflection > Reflection and Late Binding

REFLECTION AND LATE BINDING
• Reflection provides infrastructure used by language compilers such as VB 2005 to implement implicit late binding
• Binding is the process of locating the declaration (that is, the implementation) that corresponds to a uniquely specified type
• When this process occurs at run time rather then at compile time, it is called late binding


CREATING NEW TYPES AT RUNTIME USING REFLECTION
• To create new types at runtime, System.Reflection and System.Reflection.Emit provides various types/methods
• Some important members are as under:


AssemblyName >> Used to specify the name
AssemblyBuilder >> AppDomain.CurrentDomain.DefineDynamicAssembly
ModuleBuilder >> Used to define module
AppDomain >> Has static methods like DefineDynamicAssembly
TypeBuilder >> Used to specify name of methods, the new type will have
MethodBuilder >> Define the access specifiers, parameters
ParameterBuilder >> Define the parameter in/out
ILGenerator >> Object of this is required for constructing new type
ILGenerator.Emit >> Passed OpCodes.Ldarg_1, Ldarg_2 parameters
TypeBuilder.CreateType() >> Called at last, to construct the Type

No comments:

Post a Comment