System.Reflection.Emit.TypeBuilder.CreateType Method

Creates a Type object for the class. After defining fields and methods on the class, CreateType is called in order to load its Type object.

Syntax

public Type CreateType ()

Returns

Returns the new Type object for this class.

Remarks

If this type is a nested type, the TypeBuilder.CreateType method must be called on the enclosing type before it is called on the nested type.

If the current type derives from an incomplete type or implements incomplete interfaces, call the TypeBuilder.CreateType method on the parent type and the interface types before calling it on the current type.

If the enclosing type contains a field that is a value type defined as a nested type (for example, a field that is an enumeration defined as a nested type), calling the TypeBuilder.CreateType method on the enclosing type will generate a AppDomain.TypeResolve event. This is because the loader cannot determine the size of the enclosing type until the nested type has been completed. The caller should define a handler for the AppDomain.TypeResolve event to complete the definition of the nested type by calling TypeBuilder.CreateType on the System.Reflection.Emit.TypeBuilder object that represents the nested type. The code example for this topic shows how to define such an event handler.

A type is created only once, no matter how many times the TypeBuilder.CreateType method is called. All calls return the same Type object.

Requirements

Namespace: System.Reflection.Emit
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0