ModuleBuilder.DefineType ModuleBuilder.DefineType ModuleBuilder.DefineType ModuleBuilder.DefineType Method

定义

构造一个 TypeBuilderConstructs a TypeBuilder. 若要定义值类型,请定义一个派生自 ValueType 的类型。To define a value type, define a type that derives from ValueType.

重载

DefineType(String, TypeAttributes, Type, PackingSize, Int32) DefineType(String, TypeAttributes, Type, PackingSize, Int32) DefineType(String, TypeAttributes, Type, PackingSize, Int32)

在给定类型名称、特性、已定义类型扩展的类型,已定义类型的封装大小和已定义类型的总大小的情况下,构造 TypeBuilderConstructs 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.

DefineType(String, TypeAttributes, Type, Type[]) DefineType(String, TypeAttributes, Type, Type[]) DefineType(String, TypeAttributes, Type, Type[]) DefineType(String, TypeAttributes, Type, Type[])

在给定类型名称、特性、已定义类型扩展的类型和已定义类型实现的接口的情况下,构造 TypeBuilderConstructs a TypeBuilder given the type name, attributes, the type that the defined type extends, and the interfaces that the defined type implements.

DefineType(String, TypeAttributes, Type, Int32) DefineType(String, TypeAttributes, Type, Int32) DefineType(String, TypeAttributes, Type, Int32) DefineType(String, TypeAttributes, Type, Int32)

在给定类型名称、特性、已定义类型扩展的类型和类型的总大小的情况下,构造 TypeBuilderConstructs a TypeBuilder given the type name, the attributes, the type that the defined type extends, and the total size of the type.

DefineType(String, TypeAttributes, Type, PackingSize) DefineType(String, TypeAttributes, Type, PackingSize) DefineType(String, TypeAttributes, Type, PackingSize) DefineType(String, TypeAttributes, Type, PackingSize)

在给定类型名称、特性、已定义类型扩展的类型和类型的封装大小的情况下,构造 TypeBuilderConstructs a TypeBuilder given the type name, the attributes, the type that the defined type extends, and the packing size of the type.

DefineType(String, TypeAttributes) DefineType(String, TypeAttributes) DefineType(String, TypeAttributes) DefineType(String, TypeAttributes)

在给定类型名称和类型特性的情况下,构造 TypeBuilderConstructs a TypeBuilder given the type name and the type attributes.

DefineType(String) DefineType(String) DefineType(String) DefineType(String)

在此模块中用指定的名称为私有类型构造 TypeBuilderConstructs a TypeBuilder for a private type with the specified name in this module.

DefineType(String, TypeAttributes, Type) DefineType(String, TypeAttributes, Type) DefineType(String, TypeAttributes, Type) DefineType(String, TypeAttributes, Type)

在给定类型名称、类型特性和已定义类型扩展的类型的情况下,构造 TypeBuilderConstructs a TypeBuilder given type name, its attributes, and the type that the defined type extends.

DefineType(String, TypeAttributes, Type, PackingSize, Int32) DefineType(String, TypeAttributes, Type, PackingSize, Int32) DefineType(String, TypeAttributes, Type, PackingSize, Int32)

在给定类型名称、特性、已定义类型扩展的类型,已定义类型的封装大小和已定义类型的总大小的情况下,构造 TypeBuilderConstructs 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);
member this.DefineType : string * System.Reflection.TypeAttributes * Type * System.Reflection.Emit.PackingSize * int -> System.Reflection.Emit.TypeBuilder

参数

name
String String String String

类型的完整路径。The full path of the type. name 不能包含嵌入的 null。name cannot contain embedded nulls.

attr
TypeAttributes TypeAttributes TypeAttributes TypeAttributes

已定义类型的属性。The attributes of the defined type.

parent
Type Type Type Type

已定义类型扩展的类型。The type that the defined type extends.

packingSize
PackingSize PackingSize PackingSize PackingSize

此类型的封装大小。The packing size of the type.

typesize
Int32 Int32 Int32 Int32

此类型的总大小。The total size of the type.

返回

用所有请求的特性创建的 TypeBuilderA TypeBuilder created with all of the requested attributes.

异常

具有给定名称的类型存在于此模块的父程序集中。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.

示例

下面的示例使用TypeBuilder CreateType在当前动态模块中创建一个,生成并完成该类型,并保存程序集。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")

注解

类型名称在程序集内必须是唯一的。Type names must be unique within an assembly. 程序集的两个不同模块中不能有两个具有相同名称的类型。You cannot have two types with the same name in two different modules of an assembly.

备注

从开始ReflectionPermission ReflectionPermissionFlag.ReflectionEmit ,此成员不再需要带有标志的。 .NET Framework 2.0 Service Pack 1.NET Framework 2.0 Service Pack 1Starting with the .NET Framework 2.0 Service Pack 1.NET Framework 2.0 Service Pack 1, this member no longer requires ReflectionPermission with the ReflectionPermissionFlag.ReflectionEmit flag. (请参阅反射发出中的安全问题。)若要使用此功能,应用程序应为 .NET Framework 3.5.NET Framework 3.5 或更高版本。(See Security Issues in Reflection Emit.) To use this functionality, your application should target the .NET Framework 3.5.NET Framework 3.5 or later.

DefineType(String, TypeAttributes, Type, Type[]) DefineType(String, TypeAttributes, Type, Type[]) DefineType(String, TypeAttributes, Type, Type[]) DefineType(String, TypeAttributes, Type, Type[])

在给定类型名称、特性、已定义类型扩展的类型和已定义类型实现的接口的情况下,构造 TypeBuilderConstructs 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);
[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
Public Function DefineType (name As String, attr As TypeAttributes, parent As Type, interfaces As Type()) As TypeBuilder

参数

name
String String String String

类型的完整路径。The full path of the type. name 不能包含嵌入的 null。name cannot contain embedded nulls.

attr
TypeAttributes TypeAttributes TypeAttributes TypeAttributes

与类型关联的特性。The attributes to be associated with the type.

parent
Type Type Type Type

已定义类型扩展的类型。The type that the defined type extends.

interfaces
Type[]

类型实现的接口列表。The list of interfaces that the type implements.

返回

用所有请求的特性创建的 TypeBuilderA TypeBuilder created with all of the requested attributes.

异常

具有给定名称的类型存在于此模块的父程序集中。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.

示例

下面的示例使用TypeBuilder CreateType在当前动态模块中创建一个,生成并完成该类型,并保存程序集。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")

注解

类型名称在程序集内必须是唯一的。Type names must be unique within an assembly. 程序集的两个不同模块中不能有两个具有相同名称的类型。You cannot have two types with the same name in two different modules of an assembly.

备注

从开始ReflectionPermission ReflectionPermissionFlag.ReflectionEmit ,此成员不再需要带有标志的。 .NET Framework 2.0 Service Pack 1.NET Framework 2.0 Service Pack 1Starting with the .NET Framework 2.0 Service Pack 1.NET Framework 2.0 Service Pack 1, this member no longer requires ReflectionPermission with the ReflectionPermissionFlag.ReflectionEmit flag. (请参阅反射发出中的安全问题。)若要使用此功能,应用程序应为 .NET Framework 3.5.NET Framework 3.5 或更高版本。(See Security Issues in Reflection Emit.) To use this functionality, your application should target the .NET Framework 3.5.NET Framework 3.5 or later.

DefineType(String, TypeAttributes, Type, Int32) DefineType(String, TypeAttributes, Type, Int32) DefineType(String, TypeAttributes, Type, Int32) DefineType(String, TypeAttributes, Type, Int32)

在给定类型名称、特性、已定义类型扩展的类型和类型的总大小的情况下,构造 TypeBuilderConstructs 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);
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

参数

name
String String String String

类型的完整路径。The full path of the type. name 不能包含嵌入的 null。name cannot contain embedded nulls.

attr
TypeAttributes TypeAttributes TypeAttributes TypeAttributes

已定义类型的属性。The attributes of the defined type.

parent
Type Type Type Type

已定义类型扩展的类型。The type that the defined type extends.

typesize
Int32 Int32 Int32 Int32

此类型的总大小。The total size of the type.

返回

一个 TypeBuilder 对象。A TypeBuilder object.

异常

具有给定名称的类型存在于此模块的父程序集中。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.

示例

下面的示例使用TypeBuilder CreateType在当前动态模块中创建一个,生成并完成该类型,并保存程序集。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")

注解

类型名称在程序集内必须是唯一的。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.

备注

从开始ReflectionPermission ReflectionPermissionFlag.ReflectionEmit ,此成员不再需要带有标志的。 .NET Framework 2.0 Service Pack 1.NET Framework 2.0 Service Pack 1Starting with the .NET Framework 2.0 Service Pack 1.NET Framework 2.0 Service Pack 1, this member no longer requires ReflectionPermission with the ReflectionPermissionFlag.ReflectionEmit flag. (请参阅反射发出中的安全问题。)若要使用此功能,应用程序应为 .NET Framework 3.5.NET Framework 3.5 或更高版本。(See Security Issues in Reflection Emit.) To use this functionality, your application should target the .NET Framework 3.5.NET Framework 3.5 or later.

DefineType(String, TypeAttributes, Type, PackingSize) DefineType(String, TypeAttributes, Type, PackingSize) DefineType(String, TypeAttributes, Type, PackingSize) DefineType(String, TypeAttributes, Type, PackingSize)

在给定类型名称、特性、已定义类型扩展的类型和类型的封装大小的情况下,构造 TypeBuilderConstructs 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);
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

参数

name
String String String String

类型的完整路径。The full path of the type. name 不能包含嵌入的 null。name cannot contain embedded nulls.

attr
TypeAttributes TypeAttributes TypeAttributes TypeAttributes

已定义类型的属性。The attributes of the defined type.

parent
Type Type Type Type

已定义类型扩展的类型。The type that the defined type extends.

packsize
PackingSize PackingSize PackingSize PackingSize

此类型的封装大小。The packing size of the type.

返回

一个 TypeBuilder 对象。A TypeBuilder object.

异常

具有给定名称的类型存在于此模块的父程序集中。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.

示例

下面的示例使用TypeBuilder CreateType在当前动态模块中创建一个,生成并完成该类型,并保存程序集。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")

注解

类型名称在程序集内必须是唯一的。Type names must be unique within an assembly. 程序集的两个不同模块中不能有两个具有相同名称的类型。You cannot have two types with the same name in two different modules of an assembly.

备注

从开始ReflectionPermission ReflectionPermissionFlag.ReflectionEmit ,此成员不再需要带有标志的。 .NET Framework 2.0 Service Pack 1.NET Framework 2.0 Service Pack 1Starting with the .NET Framework 2.0 Service Pack 1.NET Framework 2.0 Service Pack 1, this member no longer requires ReflectionPermission with the ReflectionPermissionFlag.ReflectionEmit flag. (请参阅反射发出中的安全问题。)若要使用此功能,应用程序应为 .NET Framework 3.5.NET Framework 3.5 或更高版本。(See Security Issues in Reflection Emit.) To use this functionality, your application should target the .NET Framework 3.5.NET Framework 3.5 or later.

DefineType(String, TypeAttributes) DefineType(String, TypeAttributes) DefineType(String, TypeAttributes) DefineType(String, TypeAttributes)

在给定类型名称和类型特性的情况下,构造 TypeBuilderConstructs 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

参数

name
String String String String

类型的完整路径。The full path of the type. name 不能包含嵌入的 null。name cannot contain embedded nulls.

attr
TypeAttributes TypeAttributes TypeAttributes TypeAttributes

已定义类型的属性。The attributes of the defined type.

返回

用所有请求的特性创建的 TypeBuilderA TypeBuilder created with all of the requested attributes.

异常

具有给定名称的类型存在于此模块的父程序集中。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.

示例

下面的示例使用TypeBuilder CreateType在当前动态模块中创建一个,生成并完成该类型,并保存程序集。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")

注解

类型名称在程序集内必须是唯一的。Type names must be unique within an assembly. 程序集的两个不同模块中不能有两个具有相同名称的类型。You cannot have two types with the same name in two different modules of an assembly.

备注

从开始ReflectionPermission ReflectionPermissionFlag.ReflectionEmit ,此成员不再需要带有标志的。 .NET Framework 2.0 Service Pack 1.NET Framework 2.0 Service Pack 1Starting with the .NET Framework 2.0 Service Pack 1.NET Framework 2.0 Service Pack 1, this member no longer requires ReflectionPermission with the ReflectionPermissionFlag.ReflectionEmit flag. (请参阅反射发出中的安全问题。)若要使用此功能,应用程序应为 .NET Framework 3.5.NET Framework 3.5 或更高版本。(See Security Issues in Reflection Emit.) To use this functionality, your application should target the .NET Framework 3.5.NET Framework 3.5 or later.

DefineType(String) DefineType(String) DefineType(String) DefineType(String)

在此模块中用指定的名称为私有类型构造 TypeBuilderConstructs 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

参数

name
String String String String

类型的完整路径,其中包括命名空间。The full path of the type, including the namespace. name 不能包含嵌入的 null。name cannot contain embedded nulls.

返回

具有指定名称的私有类型。A private type with the specified name.

异常

具有给定名称的类型存在于此模块的父程序集中。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.

示例

下面的示例使用TypeBuilder CreateType在当前动态模块中创建一个,生成并完成该类型,并保存程序集。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")

注解

类型名称在程序集内必须是唯一的。Type names must be unique within an assembly. 程序集的两个不同模块中不能有两个具有相同名称的类型。You cannot have two types with the same name in two different modules of an assembly.

备注

从开始ReflectionPermission ReflectionPermissionFlag.ReflectionEmit ,此成员不再需要带有标志的。 .NET Framework 2.0 Service Pack 1.NET Framework 2.0 Service Pack 1Starting with the .NET Framework 2.0 Service Pack 1.NET Framework 2.0 Service Pack 1, this member no longer requires ReflectionPermission with the ReflectionPermissionFlag.ReflectionEmit flag. (请参阅反射发出中的安全问题。)若要使用此功能,应用程序应为 .NET Framework 3.5.NET Framework 3.5 或更高版本。(See Security Issues in Reflection Emit.) To use this functionality, your application should target the .NET Framework 3.5.NET Framework 3.5 or later.

DefineType(String, TypeAttributes, Type) DefineType(String, TypeAttributes, Type) DefineType(String, TypeAttributes, Type) DefineType(String, TypeAttributes, Type)

在给定类型名称、类型特性和已定义类型扩展的类型的情况下,构造 TypeBuilderConstructs 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);
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

参数

name
String String String String

类型的完整路径。The full path of the type. name 不能包含嵌入的 null。name cannot contain embedded nulls.

attr
TypeAttributes TypeAttributes TypeAttributes TypeAttributes

与类型关联的属性。The attribute to be associated with the type.

parent
Type Type Type Type

已定义类型扩展的类型。The type that the defined type extends.

返回

用所有请求的特性创建的 TypeBuilderA TypeBuilder created with all of the requested attributes.

异常

具有给定名称的类型存在于此模块的父程序集中。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.

示例

下面的示例使用TypeBuilder CreateType在当前动态模块中创建一个,生成并完成该类型,并保存程序集。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")

注解

类型名称在程序集内必须是唯一的。Type names must be unique within an assembly. 程序集的两个不同模块中不能有两个具有相同名称的类型。You cannot have two types with the same name in two different modules of an assembly.

备注

从开始ReflectionPermission ReflectionPermissionFlag.ReflectionEmit ,此成员不再需要带有标志的。 .NET Framework 2.0 Service Pack 1.NET Framework 2.0 Service Pack 1Starting with the .NET Framework 2.0 Service Pack 1.NET Framework 2.0 Service Pack 1, this member no longer requires ReflectionPermission with the ReflectionPermissionFlag.ReflectionEmit flag. (请参阅反射发出中的安全问题。)若要使用此功能,应用程序应为 .NET Framework 3.5.NET Framework 3.5 或更高版本。(See Security Issues in Reflection Emit.) To use this functionality, your application should target the .NET Framework 3.5.NET Framework 3.5 or later.

适用于