Export (0) Print
Expand All

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

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

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

public TypeBuilder DefineType (
	string name,
	TypeAttributes attr,
	Type parent,
	PackingSize packsize
)
public TypeBuilder DefineType (
	String name, 
	TypeAttributes attr, 
	Type parent, 
	PackingSize packsize
)
public function DefineType (
	name : String, 
	attr : TypeAttributes, 
	parent : Type, 
	packsize : PackingSize
) : TypeBuilder

Parameters

name

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

attr

The attributes of the defined type.

parent

The Type that the defined type extends.

packsize

The packing size of the type.

Return Value

Returns a TypeBuilder object.

Exception typeCondition

ArgumentException

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

-or-

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

ArgumentNullException

name is null.

Type names must be unique within an assembly. You cannot 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" );
typebuild1.CreateType();
asmbuild.Save( "assemfilename.exe" );

AssemblyName asmName = new AssemblyName();

asmName.set_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");
typeBuild1.CreateType();
asmBuild.Save("assemfilename.exe");

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

Community Additions

ADD
Show:
© 2014 Microsoft