Export (0) Print
Expand All

ModuleBuilder.DefineType Method (String, TypeAttributes, Type, Int32)

Constructs a TypeBuilder given the type name, the attributes, the type that the defined type extends, and the total size of the type.

Namespace:  System.Reflection.Emit
Assembly:  mscorlib (in mscorlib.dll)

Public Function DefineType ( _
	name As String, _
	attr As TypeAttributes, _
	parent As Type, _
	typesize As Integer _
) As TypeBuilder


Type: System.String

The full path of the type. name cannot contain embedded nulls.

Type: System.Reflection.TypeAttributes

The attributes of the defined type.

Type: System.Type

The type that the defined type extends.

Type: System.Int32

The total size of the type.

Return Value

Type: System.Reflection.Emit.TypeBuilder
A TypeBuilder object.


A type with the given name exists in the parent assembly of this module.


Nested type attributes are set on a type that is not nested.


name is Nothing.

Type names must be unique within an assembly. It is forbidden to have two types with the same name in two different modules of an assembly.


Starting with the .NET Framework 2.0 Service Pack 1, this member no longer requires ReflectionPermission with the ReflectionPermissionFlag.ReflectionEmit flag. (See Security Issues in Reflection Emit.) To use this functionality, your application should target the .NET Framework 3.5 or later.

The following example creates a TypeBuilder in the current dynamic module using CreateType, builds and completes the type, and saves the assembly.

Dim asmname As New AssemblyName()
asmname.Name = "assemfilename.exe" 
Dim asmbuild As AssemblyBuilder = _
   System.Threading.Thread.GetDomain().DefineDynamicAssembly(asmname, _
Dim modbuild As ModuleBuilder = _
   asmbuild.DefineDynamicModule("modulename", "assemfilename.exe")
Dim typebuild1 As TypeBuilder = modbuild.DefineType("typename")

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft