This documentation is archived and is not being maintained.

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 TypeBuilder DefineType (
	string name,
	TypeAttributes attr,
	Type parent,
	int typesize
public TypeBuilder DefineType (
	String name, 
	TypeAttributes attr, 
	Type parent, 
	int typesize
public function DefineType (
	name : String, 
	attr : TypeAttributes, 
	parent : Type, 
	typesize : int
) : TypeBuilder



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


The attributes of the defined type.


The Type that the defined type extends.


The total size of the type.

Return Value

Returns a TypeBuilder object.

Exception typeCondition


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 null.

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.

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

AssemblyName asmname = new AssemblyName();
asmname.Name = "assemfilename.exe";        
AssemblyBuilder asmbuild = System.Threading.Thread.GetDomain().
            DefineDynamicAssembly(asmname, AssemblyBuilderAccess.RunAndSave);
ModuleBuilder modbuild = asmbuild.DefineDynamicModule( "modulename",
   "assemfilename.exe" );
TypeBuilder typebuild1 = modbuild.DefineType( "typename" );
asmbuild.Save( "assemfilename.exe" );

AssemblyName asmName = new AssemblyName();

AssemblyBuilder asmBuild = 
    (asmName, AssemblyBuilderAccess.RunAndSave);
ModuleBuilder modBuild = asmBuild.DefineDynamicModule("modulename",
TypeBuilder typeBuild1 = modBuild.DefineType("typename");

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0