ModuleBuilder.DefineType Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Constructs a TypeBuilder
. To define a value type, define a type that derives from ValueType.
DefineType(String, TypeAttributes, Type, Type[]) |
Constructs a |
DefineType(String, TypeAttributes, Type, PackingSize, Int32) |
Constructs a |
DefineType(String, TypeAttributes, Type, PackingSize) |
Constructs a |
DefineType(String, TypeAttributes) |
Constructs a |
DefineType(String, TypeAttributes, Type) |
Constructs a |
DefineType(String, TypeAttributes, Type, Int32) |
Constructs a |
DefineType(String) |
Constructs a |
- Source:
- ModuleBuilder.cs
- Source:
- ModuleBuilder.cs
- Source:
- ModuleBuilder.cs
Constructs a TypeBuilder
given the type name, attributes, the type that the defined type extends, and the interfaces that the defined type implements.
public:
System::Reflection::Emit::TypeBuilder ^ DefineType(System::String ^ name, System::Reflection::TypeAttributes attr, Type ^ parent, cli::array <Type ^> ^ interfaces);
public System.Reflection.Emit.TypeBuilder DefineType (string name, System.Reflection.TypeAttributes attr, Type? parent, Type[]? interfaces);
public System.Reflection.Emit.TypeBuilder DefineType (string name, System.Reflection.TypeAttributes attr, Type parent, Type[] interfaces);
[System.Runtime.InteropServices.ComVisible(true)]
public System.Reflection.Emit.TypeBuilder DefineType (string name, System.Reflection.TypeAttributes attr, Type parent, Type[] interfaces);
member this.DefineType : string * System.Reflection.TypeAttributes * Type * Type[] -> System.Reflection.Emit.TypeBuilder
[<System.Runtime.InteropServices.ComVisible(true)>]
member this.DefineType : string * System.Reflection.TypeAttributes * Type * Type[] -> System.Reflection.Emit.TypeBuilder
Public Function DefineType (name As String, attr As TypeAttributes, parent As Type, interfaces As Type()) As TypeBuilder
Parameters
- name
- String
The full path of the type. name
cannot contain embedded nulls.
- attr
- TypeAttributes
The attributes to be associated with the type.
- parent
- Type
The type that the defined type extends.
- interfaces
- Type[]
The list of interfaces that the type implements.
Returns
A TypeBuilder
created with all of the requested attributes.
- Attributes
Exceptions
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.
name
is null
.
Examples
The following example creates a TypeBuilder in the current dynamic module using CreateType
, builds and completes the type, and saves the assembly.
AssemblyName^ asmname = gcnew 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.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" );
Dim asmname As New AssemblyName()
asmname.Name = "assemfilename.exe"
Dim asmbuild As AssemblyBuilder = _
System.Threading.Thread.GetDomain().DefineDynamicAssembly(asmname, _
AssemblyBuilderAccess.RunAndSave)
Dim modbuild As ModuleBuilder = _
asmbuild.DefineDynamicModule("modulename", "assemfilename.exe")
Dim typebuild1 As TypeBuilder = modbuild.DefineType("typename")
typebuild1.CreateType()
asmbuild.Save("assemfilename.exe")
Remarks
Type names must be unique within an assembly. You cannot have two types with the same name in two different modules of an assembly.
Anteckning
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.
Applies to
.NET 9 och andra versioner
Produkt | Versioner |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided), 2.1 |
- Source:
- ModuleBuilder.cs
- Source:
- ModuleBuilder.cs
- Source:
- ModuleBuilder.cs
Constructs a TypeBuilder
given the type name, attributes, the type that the defined type extends, the packing size of the defined type, and the total size of the defined type.
public:
System::Reflection::Emit::TypeBuilder ^ DefineType(System::String ^ name, System::Reflection::TypeAttributes attr, Type ^ parent, System::Reflection::Emit::PackingSize packingSize, int typesize);
public System.Reflection.Emit.TypeBuilder DefineType (string name, System.Reflection.TypeAttributes attr, Type? parent, System.Reflection.Emit.PackingSize packingSize, int typesize);
public System.Reflection.Emit.TypeBuilder DefineType (string name, System.Reflection.TypeAttributes attr, Type parent, System.Reflection.Emit.PackingSize packingSize, int typesize);
member this.DefineType : string * System.Reflection.TypeAttributes * Type * System.Reflection.Emit.PackingSize * int -> System.Reflection.Emit.TypeBuilder
Public Function DefineType (name As String, attr As TypeAttributes, parent As Type, packingSize As PackingSize, typesize As Integer) As TypeBuilder
Parameters
- name
- String
The full path of the type. name
cannot contain embedded nulls.
- attr
- TypeAttributes
The attributes of the defined type.
- parent
- Type
The type that the defined type extends.
- packingSize
- PackingSize
The packing size of the type.
- typesize
- Int32
The total size of the type.
Returns
A TypeBuilder
created with all of the requested attributes.
Exceptions
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.
name
is null
.
Examples
The following example creates a TypeBuilder in the current dynamic module using CreateType
, builds and completes the type, and saves the assembly.
AssemblyName^ asmname = gcnew 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.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" );
Dim asmname As New AssemblyName()
asmname.Name = "assemfilename.exe"
Dim asmbuild As AssemblyBuilder = _
System.Threading.Thread.GetDomain().DefineDynamicAssembly(asmname, _
AssemblyBuilderAccess.RunAndSave)
Dim modbuild As ModuleBuilder = _
asmbuild.DefineDynamicModule("modulename", "assemfilename.exe")
Dim typebuild1 As TypeBuilder = modbuild.DefineType("typename")
typebuild1.CreateType()
asmbuild.Save("assemfilename.exe")
Remarks
Type names must be unique within an assembly. You cannot have two types with the same name in two different modules of an assembly.
Anteckning
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.
Applies to
.NET 9 och andra versioner
Produkt | Versioner |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided), 2.1 |
- Source:
- ModuleBuilder.cs
- Source:
- ModuleBuilder.cs
- Source:
- ModuleBuilder.cs
Constructs a TypeBuilder
given the type name, the attributes, the type that the defined type extends, and the packing size of the type.
public:
System::Reflection::Emit::TypeBuilder ^ DefineType(System::String ^ name, System::Reflection::TypeAttributes attr, Type ^ parent, System::Reflection::Emit::PackingSize packsize);
public System.Reflection.Emit.TypeBuilder DefineType (string name, System.Reflection.TypeAttributes attr, Type? parent, System.Reflection.Emit.PackingSize packsize);
public System.Reflection.Emit.TypeBuilder DefineType (string name, System.Reflection.TypeAttributes attr, Type parent, System.Reflection.Emit.PackingSize packsize);
member this.DefineType : string * System.Reflection.TypeAttributes * Type * System.Reflection.Emit.PackingSize -> System.Reflection.Emit.TypeBuilder
Public Function DefineType (name As String, attr As TypeAttributes, parent As Type, packsize As PackingSize) As TypeBuilder
Parameters
- name
- String
The full path of the type. name
cannot contain embedded nulls.
- attr
- TypeAttributes
The attributes of the defined type.
- parent
- Type
The type that the defined type extends.
- packsize
- PackingSize
The packing size of the type.
Returns
A TypeBuilder
object.
Exceptions
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.
name
is null
.
Examples
The following example creates a TypeBuilder in the current dynamic module using CreateType
, builds and completes the type, and saves the assembly.
AssemblyName^ asmname = gcnew 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.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" );
Dim asmname As New AssemblyName()
asmname.Name = "assemfilename.exe"
Dim asmbuild As AssemblyBuilder = _
System.Threading.Thread.GetDomain().DefineDynamicAssembly(asmname, _
AssemblyBuilderAccess.RunAndSave)
Dim modbuild As ModuleBuilder = _
asmbuild.DefineDynamicModule("modulename", "assemfilename.exe")
Dim typebuild1 As TypeBuilder = modbuild.DefineType("typename")
typebuild1.CreateType()
asmbuild.Save("assemfilename.exe")
Remarks
Type names must be unique within an assembly. You cannot have two types with the same name in two different modules of an assembly.
Anteckning
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.
Applies to
.NET 9 och andra versioner
Produkt | Versioner |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided), 2.1 |
- Source:
- ModuleBuilder.cs
- Source:
- ModuleBuilder.cs
- Source:
- ModuleBuilder.cs
Constructs a TypeBuilder
given the type name and the type attributes.
public:
System::Reflection::Emit::TypeBuilder ^ DefineType(System::String ^ name, System::Reflection::TypeAttributes attr);
public System.Reflection.Emit.TypeBuilder DefineType (string name, System.Reflection.TypeAttributes attr);
member this.DefineType : string * System.Reflection.TypeAttributes -> System.Reflection.Emit.TypeBuilder
Public Function DefineType (name As String, attr As TypeAttributes) As TypeBuilder
Parameters
- name
- String
The full path of the type. name
cannot contain embedded nulls.
- attr
- TypeAttributes
The attributes of the defined type.
Returns
A TypeBuilder
created with all of the requested attributes.
Exceptions
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.
name
is null
.
Examples
The following example creates a TypeBuilder in the current dynamic module using CreateType
, builds and completes the type, and saves the assembly.
AssemblyName^ asmname = gcnew 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.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" );
Dim asmname As New AssemblyName()
asmname.Name = "assemfilename.exe"
Dim asmbuild As AssemblyBuilder = _
System.Threading.Thread.GetDomain().DefineDynamicAssembly(asmname, _
AssemblyBuilderAccess.RunAndSave)
Dim modbuild As ModuleBuilder = _
asmbuild.DefineDynamicModule("modulename", "assemfilename.exe")
Dim typebuild1 As TypeBuilder = modbuild.DefineType("typename")
typebuild1.CreateType()
asmbuild.Save("assemfilename.exe")
Remarks
Type names must be unique within an assembly. You cannot have two types with the same name in two different modules of an assembly.
Anteckning
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.
Applies to
.NET 9 och andra versioner
Produkt | Versioner |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided), 2.1 |
- Source:
- ModuleBuilder.cs
- Source:
- ModuleBuilder.cs
- Source:
- ModuleBuilder.cs
Constructs a TypeBuilder
given type name, its attributes, and the type that the defined type extends.
public:
System::Reflection::Emit::TypeBuilder ^ DefineType(System::String ^ name, System::Reflection::TypeAttributes attr, Type ^ parent);
public System.Reflection.Emit.TypeBuilder DefineType (string name, System.Reflection.TypeAttributes attr, Type? parent);
public System.Reflection.Emit.TypeBuilder DefineType (string name, System.Reflection.TypeAttributes attr, Type parent);
member this.DefineType : string * System.Reflection.TypeAttributes * Type -> System.Reflection.Emit.TypeBuilder
Public Function DefineType (name As String, attr As TypeAttributes, parent As Type) As TypeBuilder
Parameters
- name
- String
The full path of the type. name
cannot contain embedded nulls.
- attr
- TypeAttributes
The attribute to be associated with the type.
- parent
- Type
The type that the defined type extends.
Returns
A TypeBuilder
created with all of the requested attributes.
Exceptions
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.
name
is null
.
Examples
The following example creates a TypeBuilder in the current dynamic module using CreateType
, builds and completes the type, and saves the assembly.
AssemblyName^ asmname = gcnew 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.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" );
Dim asmname As New AssemblyName()
asmname.Name = "assemfilename.exe"
Dim asmbuild As AssemblyBuilder = _
System.Threading.Thread.GetDomain().DefineDynamicAssembly(asmname, _
AssemblyBuilderAccess.RunAndSave)
Dim modbuild As ModuleBuilder = _
asmbuild.DefineDynamicModule("modulename", "assemfilename.exe")
Dim typebuild1 As TypeBuilder = modbuild.DefineType("typename")
typebuild1.CreateType()
asmbuild.Save("assemfilename.exe")
Remarks
Type names must be unique within an assembly. You cannot have two types with the same name in two different modules of an assembly.
Anteckning
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.
Applies to
.NET 9 och andra versioner
Produkt | Versioner |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided), 2.1 |
- Source:
- ModuleBuilder.cs
- Source:
- ModuleBuilder.cs
- Source:
- ModuleBuilder.cs
Constructs a TypeBuilder
given the type name, the attributes, the type that the defined type extends, and the total size of the type.
public:
System::Reflection::Emit::TypeBuilder ^ DefineType(System::String ^ name, System::Reflection::TypeAttributes attr, Type ^ parent, int typesize);
public System.Reflection.Emit.TypeBuilder DefineType (string name, System.Reflection.TypeAttributes attr, Type? parent, int typesize);
public System.Reflection.Emit.TypeBuilder DefineType (string name, System.Reflection.TypeAttributes attr, Type parent, int typesize);
member this.DefineType : string * System.Reflection.TypeAttributes * Type * int -> System.Reflection.Emit.TypeBuilder
Public Function DefineType (name As String, attr As TypeAttributes, parent As Type, typesize As Integer) As TypeBuilder
Parameters
- name
- String
The full path of the type. name
cannot contain embedded nulls.
- attr
- TypeAttributes
The attributes of the defined type.
- parent
- Type
The type that the defined type extends.
- typesize
- Int32
The total size of the type.
Returns
A TypeBuilder
object.
Exceptions
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.
name
is null
.
Examples
The following example creates a TypeBuilder in the current dynamic module using CreateType
, builds and completes the type, and saves the assembly.
AssemblyName^ asmname = gcnew 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.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" );
Dim asmname As New AssemblyName()
asmname.Name = "assemfilename.exe"
Dim asmbuild As AssemblyBuilder = _
System.Threading.Thread.GetDomain().DefineDynamicAssembly(asmname, _
AssemblyBuilderAccess.RunAndSave)
Dim modbuild As ModuleBuilder = _
asmbuild.DefineDynamicModule("modulename", "assemfilename.exe")
Dim typebuild1 As TypeBuilder = modbuild.DefineType("typename")
typebuild1.CreateType()
asmbuild.Save("assemfilename.exe")
Remarks
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.
Anteckning
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.
Applies to
.NET 9 och andra versioner
Produkt | Versioner |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided), 2.1 |
- Source:
- ModuleBuilder.cs
- Source:
- ModuleBuilder.cs
- Source:
- ModuleBuilder.cs
Constructs a TypeBuilder
for a private type with the specified name in this module.
public:
System::Reflection::Emit::TypeBuilder ^ DefineType(System::String ^ name);
public System.Reflection.Emit.TypeBuilder DefineType (string name);
member this.DefineType : string -> System.Reflection.Emit.TypeBuilder
Public Function DefineType (name As String) As TypeBuilder
Parameters
- name
- String
The full path of the type, including the namespace. name
cannot contain embedded nulls.
Returns
A private type with the specified name.
Exceptions
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.
name
is null
.
Examples
The following example creates a TypeBuilder in the current dynamic module using CreateType
, builds and completes the type, and saves the assembly.
AssemblyName^ asmname = gcnew 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.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" );
Dim asmname As New AssemblyName()
asmname.Name = "assemfilename.exe"
Dim asmbuild As AssemblyBuilder = _
System.Threading.Thread.GetDomain().DefineDynamicAssembly(asmname, _
AssemblyBuilderAccess.RunAndSave)
Dim modbuild As ModuleBuilder = _
asmbuild.DefineDynamicModule("modulename", "assemfilename.exe")
Dim typebuild1 As TypeBuilder = modbuild.DefineType("typename")
typebuild1.CreateType()
asmbuild.Save("assemfilename.exe")
Remarks
Type names must be unique within an assembly. You cannot have two types with the same name in two different modules of an assembly.
Anteckning
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.
Applies to
.NET 9 och andra versioner
Produkt | Versioner |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided), 2.1 |
Feedback om .NET
.NET är ett öppen källkod projekt. Välj en länk för att ge feedback: