Sunday, August 9, 2009

Chapter 14-Lesson 5

  • All ...Builder classes derive from their ...Info counterparts and are used to create Assemblies, Modules, Types and Members at runtime.
  • System.Reflection.Emit namespace is required.
  • AppDomain.CurrentDomain.DefineDynamicAssembly( ) method creates new Assembly in the current AppDomain with the specified AssemblyName and AssemblyAccess.
  • AssemblyAccess enumeration defines why the dynamic Assembly is being created (i.e. For Running, Reflection only, etc.). If wish to save the Assembly at a later point, we may use AssemblyAccess.RunAndSave.
  • Similarly DefineDynamicModule( ) method over the AssemblyBuilder object would create a new Module inside the dynamic Assembly.
  • Again, similarly, DefineType( ) method over a ModuleBuilder object would create a new Type with the specified Name, TypeAttributes, Parent Type (if any) and any base interfaces.
  • TypeAttributes define what the type would be (class, struct, etc.), what would be its visibility (public, private, etc.) and other attributes related to a Type.
  • GetILGenerator( ) method over a MethodBuilder (or ConstructorBuilder) object would return an ILGenerator which can be used to write code into the method.
  • MSIL opcodes are defined as static members inside the ILGenerator.
  • See page 881 for PropertyBuilder usage.
  • We may call the Save( ) method over AssemblyBuilder object to save the Assembly to the disk.

No comments:

Post a Comment