Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Reflection Emit Abstractions

The reflection emit abstractions correspond closely to the common type system that underlies the common language runtime. For example, in reflection, the Type class represents a type and can be used to enumerate the members of the type. The corresponding abstraction in reflection emit is TypeBuilder, which is used to emit new types. Similarly, in reflection, the Assembly class represents an assembly. In reflection emit, the corresponding abstraction is AssemblyBuilder.

All managed code is located in assemblies. There are two broad categories of usage for emitted code, which make slightly different use of assemblies:

  • Dynamic methods are global methods that can be executed using delegates. They are independent of any type, and the memory they use can be reclaimed by garbage collection when the methods are no longer used. They are hosted in a special system-provided assembly, which is never unloaded. The principal abstraction in this category is DynamicMethod.

  • Dynamic assemblies are complete assemblies and are subject to the same rules as other assemblies. For example, once you have emitted a dynamic assembly, you cannot unload any of the code in it. The abstractions in this category form a hierarchy, with AssemblyBuilder at the top. In a dynamic assembly, a method is represented by a MethodBuilder and must be contained in a type or module.

There are a number of abstractions, such as ILGenerator, ParameterBuilder, LocalBuilder, and Label, that are used in the construction of both dynamic methods and dynamic assemblies.

The following table shows the most important abstractions used by reflection emit in alphabetical order.

Abstraction

Description

AssemblyBuilder

A class that defines and represents a dynamic assembly. Inherits from the Assembly class.

ConstructorBuilder

A class that defines and represents a constructor, which describes an operation that creates an instance of a type. Inherits from the ConstructorInfo class.

CustomAttributeBuilder

A class that helps define custom attributes.

DynamicMethod

A class that defines a global method that can be executed using a delegate, and that can be reclaimed by garbage collection. Inherits from MethodInfo.

EnumBuilder

A class that helps define and represent an enumeration type. Inherits from the Type class.

EventBuilder

A class that is used to define and represent an event. Events specify named state transitions in which subscribers can register or unregister interest using accessor methods.

FieldBuilder

A class that is used to define and represent a field. Inherits from the FieldInfo class. A field is a named subdivision of a value. A type can have field members. A module or a type can also reference fields defined in the .sdata section of a portable executable (PE) file.

ILGenerator

A class that is used to define and represent Microsoft intermediate language (MSIL). The runtime just-in-time (JIT) compiler translates instructions in MSIL to native code.

Label

A class that is an opaque representation of a label used by the ILGenerator class. Labels correspond to specific locations in the MSIL code.

LocalBuilder

A class that represents a local variable declared within the body of a method. Inherits from LocalVariableInfo.

MethodBuilder

A class that is used to define and represent a method in a dynamic assembly. Inherits from the MethodInfo class. A method describes an operation that can be performed on values of a type.

ModuleBuilder

A class that is used to define and represent a module. Inherits from the Module class.

A module is a compilation unit or a development unit. A module that is created using the reflection emit API is called a dynamic module for the duration of the run in which the module was created.

ParameterBuilder

A class that is used to define and represent a parameter.

PropertyBuilder

A class that is used to define and represent a property. Inherits from the PropertyInfo class. Properties of an object type specify named values that can be accessed by using accessor methods that read and write the value.

TypeBuilder

A class that is used to define and represent a type. Inherits from the Type class. Types describe values. The type defines the allowed values and operations supported by instances of the type. Types can have members that are types, methods, fields, properties, or events.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft