ModuleBuilder.DefineType Method (String, TypeAttributes, Type, PackingSize)
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
Not applicable.
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.Type names must be unique within an assembly. You cannot have two types with the same name in two different modules of an assembly.
Note: |
|---|
| Starting with the , 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 . For more information, see The .NET Framework 3.5 Architecture. |
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 Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.
Note: