AssemblyBuilder.DefineDynamicModule 方法

定义

在此程序集中定义动态模块。Defines a dynamic module in this assembly.

重载

DefineDynamicModule(String)

在此程序集中定义命名的暂时动态模块。Defines a named transient dynamic module in this assembly.

DefineDynamicModule(String, Boolean)

在此程序集中定义一个暂时动态模块,并指定是否应发出符号信息。Defines a named transient dynamic module in this assembly and specifies whether symbol information should be emitted.

DefineDynamicModule(String, String)

定义具有给定名称的持久动态模块,该模块将保存到指定文件中。Defines a persistable dynamic module with the given name that will be saved to the specified file. 未发出符号信息。No symbol information is emitted.

DefineDynamicModule(String, String, Boolean)

定义一个持久的动态模块,指定模块名称、模块将保存到的文件的名称,并指定是否使用默认符号编写器发出符号信息。Defines a persistable dynamic module, specifying the module name, the name of the file to which the module will be saved, and whether symbol information should be emitted using the default symbol writer.

DefineDynamicModule(String)

在此程序集中定义命名的暂时动态模块。Defines a named transient dynamic module in this assembly.

public:
 System::Reflection::Emit::ModuleBuilder ^ DefineDynamicModule(System::String ^ name);
public System.Reflection.Emit.ModuleBuilder DefineDynamicModule (string name);
member this.DefineDynamicModule : string -> System.Reflection.Emit.ModuleBuilder
Public Function DefineDynamicModule (name As String) As ModuleBuilder

参数

name
String

动态模块的名称。The name of the dynamic module.

返回

ModuleBuilder

一个表示定义的动态模块的 ModuleBuilderA ModuleBuilder representing the defined dynamic module.

例外

name 以空格开始。name begins with white space.

- 或 --or- name 的长度为零。The length of name is zero.

- 或 --or- name 的长度超过系统定义的最大长度。The length of name is greater than the system-defined maximum length.

namenullname is null.

调用方没有所要求的权限。The caller does not have the required permission.

无法加载默认符号编写器的程序集。The assembly for default symbol writer cannot be loaded.

- 或 --or-

找不到实现默认符号编写器接口的类型。The type that implements the default symbol writer interface cannot be found.

示例

下面的代码示例演示如何使用创建暂时性的动态模块 DefineDynamicModuleThe code example below demonstrates how to create a transient dynamic module using DefineDynamicModule.

AppDomain^ myAppDomain = Thread::GetDomain();
AssemblyName^ myAsmName = gcnew AssemblyName;
myAsmName->Name = "MyAssembly";
AssemblyBuilder^ myAsmBuilder = myAppDomain->DefineDynamicAssembly(
   myAsmName, AssemblyBuilderAccess::Run );

// Create a transient dynamic module. Since no DLL name is specified with
// this constructor, it cannot be saved.
ModuleBuilder^ myModuleBuilder = myAsmBuilder->DefineDynamicModule( "MyModule1" );
AppDomain myAppDomain = Thread.GetDomain();
AssemblyName myAsmName = new AssemblyName();
myAsmName.Name = "MyAssembly";
AssemblyBuilder myAsmBuilder = myAppDomain.DefineDynamicAssembly(
                     myAsmName,
                     AssemblyBuilderAccess.Run);

// Create a transient dynamic module. Since no DLL name is specified with
// this constructor, it can not be saved.
ModuleBuilder myModuleBuilder = myAsmBuilder.DefineDynamicModule("MyModule1");
Dim myAppDomain As AppDomain = Thread.GetDomain()
Dim myAsmName As New AssemblyName()
myAsmName.Name = "MyAssembly"
Dim myAsmBuilder As AssemblyBuilder = myAppDomain.DefineDynamicAssembly(myAsmName, _
                      AssemblyBuilderAccess.Run)

' Create a transient dynamic module. Since no DLL name is specified with
' this constructor, it can not be saved. 
Dim myModuleBuilder As ModuleBuilder = myAsmBuilder.DefineDynamicModule("MyModule1")

注解

在一个程序集中定义具有相同名称的多个动态模块是错误的。It is an error to define multiple dynamic modules with the same name in an assembly.

定义的动态模块是暂时性的。The defined dynamic module is transient. 即使父动态程序集是用创建的,也不会保存动态模块 RunAndSaveThe dynamic module is not saved, even if the parent dynamic assembly was created with RunAndSave.

备注

若要在调试动态模块时取消优化,请在 DebuggableAttribute 调用之前将特性应用于动态程序集 DefineDynamicModuleTo suppress optimizations when debugging dynamic modules, apply the DebuggableAttribute attribute to the dynamic assembly before calling DefineDynamicModule. 使用标志创建的一个实例 DebuggableAttribute DisableOptimizations ,并使用方法应用它 SetCustomAttributeCreate an instance of DebuggableAttribute with the DisableOptimizations flag and apply it using the SetCustomAttribute method. 特性必须应用于动态程序集。The attribute must be applied to the dynamic assembly. 如果应用于模块,则它不起作用。It has no effect if applied to the module.

备注

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

适用于

DefineDynamicModule(String, Boolean)

在此程序集中定义一个暂时动态模块,并指定是否应发出符号信息。Defines a named transient dynamic module in this assembly and specifies whether symbol information should be emitted.

public:
 System::Reflection::Emit::ModuleBuilder ^ DefineDynamicModule(System::String ^ name, bool emitSymbolInfo);
public System.Reflection.Emit.ModuleBuilder DefineDynamicModule (string name, bool emitSymbolInfo);
member this.DefineDynamicModule : string * bool -> System.Reflection.Emit.ModuleBuilder
Public Function DefineDynamicModule (name As String, emitSymbolInfo As Boolean) As ModuleBuilder

参数

name
String

动态模块的名称。The name of the dynamic module.

emitSymbolInfo
Boolean

如果要发出符号信息,则为 true;否则为 falsetrue if symbol information is to be emitted; otherwise, false.

返回

ModuleBuilder

一个表示定义的动态模块的 ModuleBuilderA ModuleBuilder representing the defined dynamic module.

例外

name 以空格开始。name begins with white space.

- 或 --or- name 的长度为零。The length of name is zero.

- 或 --or- name 的长度超过系统定义的最大长度。The length of name is greater than the system-defined maximum length.

namenullname is null.

无法加载默认符号编写器的程序集。The assembly for default symbol writer cannot be loaded.

- 或 --or-

找不到实现默认符号编写器接口的类型。The type that implements the default symbol writer interface cannot be found.

调用方没有所要求的权限。The caller does not have the required permission.

示例

下面的代码示例演示如何使用创建暂时性的动态模块 DefineDynamicModule ,从而禁止显示符号信息。The code example below demonstrates how to create a transient dynamic module using DefineDynamicModule, suppressing symbol information.

AppDomain^ myAppDomain = Thread::GetDomain();
AssemblyName^ myAsmName = gcnew AssemblyName;
myAsmName->Name = "MyAssembly";
AssemblyBuilder^ myAsmBuilder = myAppDomain->DefineDynamicAssembly(
   myAsmName, AssemblyBuilderAccess::Run );

// Create a transient dynamic module. Since no DLL name is specified with
// this constructor, it can not be saved. By specifying the second parameter
// of the constructor as false, we can suppress the emission of symbol info.
ModuleBuilder^ myModuleBuilder = myAsmBuilder->DefineDynamicModule(
   "MyModule2", false );
AppDomain myAppDomain = Thread.GetDomain();
AssemblyName myAsmName = new AssemblyName();
myAsmName.Name = "MyAssembly";
AssemblyBuilder myAsmBuilder = myAppDomain.DefineDynamicAssembly(
                     myAsmName,
                     AssemblyBuilderAccess.Run);

// Create a transient dynamic module. Since no DLL name is specified with
// this constructor, it can not be saved. By specifying the second parameter
// of the constructor as false, we can suppress the emission of symbol info.
ModuleBuilder myModuleBuilder = myAsmBuilder.DefineDynamicModule("MyModule2",
                                 false);
Dim myAppDomain As AppDomain = Thread.GetDomain()
Dim myAsmName As New AssemblyName()
myAsmName.Name = "MyAssembly"
Dim myAsmBuilder As AssemblyBuilder = myAppDomain.DefineDynamicAssembly(myAsmName, _
                      AssemblyBuilderAccess.Run)

' Create a transient dynamic module. Since no DLL name is specified with
' this constructor, it can not be saved. By specifying the second parameter
' of the constructor as false, we can suppress the emission of symbol info.
Dim myModuleBuilder As ModuleBuilder = myAsmBuilder.DefineDynamicModule("MyModule2", _
                                  False)

注解

在一个程序集中定义具有相同名称的多个动态模块是错误的。It is an error to define multiple dynamic modules with the same name in an assembly.

即使父动态程序集是用创建的,也不会保存动态模块 RunAndSaveThe dynamic module is not saved, even if the parent dynamic assembly was created with RunAndSave.

备注

若要在调试动态模块时取消优化,请在 DebuggableAttribute 调用之前将特性应用于动态程序集 DefineDynamicModuleTo suppress optimizations when debugging dynamic modules, apply the DebuggableAttribute attribute to the dynamic assembly before calling DefineDynamicModule. 使用标志创建的一个实例 DebuggableAttribute DisableOptimizations ,并使用方法应用它 SetCustomAttributeCreate an instance of DebuggableAttribute with the DisableOptimizations flag and apply it using the SetCustomAttribute method. 特性必须应用于动态程序集。The attribute must be applied to the dynamic assembly. 如果应用于模块,则它不起作用。It has no effect if applied to the module.

备注

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

适用于

DefineDynamicModule(String, String)

定义具有给定名称的持久动态模块,该模块将保存到指定文件中。Defines a persistable dynamic module with the given name that will be saved to the specified file. 未发出符号信息。No symbol information is emitted.

public:
 System::Reflection::Emit::ModuleBuilder ^ DefineDynamicModule(System::String ^ name, System::String ^ fileName);
public System.Reflection.Emit.ModuleBuilder DefineDynamicModule (string name, string fileName);
member this.DefineDynamicModule : string * string -> System.Reflection.Emit.ModuleBuilder
Public Function DefineDynamicModule (name As String, fileName As String) As ModuleBuilder

参数

name
String

动态模块的名称。The name of the dynamic module.

fileName
String

动态模块应保存到的文件的名称。The name of the file to which the dynamic module should be saved.

返回

ModuleBuilder

ModuleBuilder 对象,它表示定义的动态模块。A ModuleBuilder object representing the defined dynamic module.

例外

namefileNamenullname or fileName is null.

namefileName 的长度为零。The length of name or fileName is zero.

- 或 --or- name 的长度超过系统定义的最大长度。The length of name is greater than the system-defined maximum length.

- 或 --or- fileName 包含路径说明(例如目录组件)。fileName contains a path specification (a directory component, for example).

- 或 --or- 与属于此程序集的另一个文件的名称发生冲突。There is a conflict with the name of another file that belongs to this assembly.

此程序集之前已经保存过。This assembly has been previously saved.

此程序集已在具有 Run 属性的动态程序集上进行了调用。This assembly was called on a dynamic assembly with Run attribute.

调用方没有所要求的权限。The caller does not have the required permission.

无法加载默认符号编写器的程序集。The assembly for default symbol writer cannot be loaded.

- 或 --or-

找不到实现默认符号编写器接口的类型。The type that implements the default symbol writer interface cannot be found.

示例

下面的代码示例演示如何使用创建持久性动态模块 DefineDynamicModuleThe code example below demonstrates how to create a persistent dynamic module using DefineDynamicModule.

AppDomain^ myAppDomain = Thread::GetDomain();
AssemblyName^ myAsmName = gcnew AssemblyName;
myAsmName->Name = "MyAssembly";
AssemblyBuilder^ myAsmBuilder = myAppDomain->DefineDynamicAssembly(
   myAsmName, AssemblyBuilderAccess::Run );

// Create a dynamic module that can be saved as the specified DLL name.
ModuleBuilder^ myModuleBuilder = myAsmBuilder->DefineDynamicModule(
   "MyModule3", "MyModule3.dll" );
AppDomain myAppDomain = Thread.GetDomain();
AssemblyName myAsmName = new AssemblyName();
myAsmName.Name = "MyAssembly";
AssemblyBuilder myAsmBuilder = myAppDomain.DefineDynamicAssembly(
                     myAsmName,
                     AssemblyBuilderAccess.Run);
// Create a dynamic module that can be saved as the specified DLL name.
ModuleBuilder myModuleBuilder = myAsmBuilder.DefineDynamicModule("MyModule3",
                                 "MyModule3.dll");
Dim myAppDomain As AppDomain = Thread.GetDomain()
Dim myAsmName As New AssemblyName()
myAsmName.Name = "MyAssembly"
Dim myAsmBuilder As AssemblyBuilder = myAppDomain.DefineDynamicAssembly(myAsmName, _
                      AssemblyBuilderAccess.Run)
' Create a dynamic module that can be saved as the specified DLL name.
Dim myModuleBuilder As ModuleBuilder = myAsmBuilder.DefineDynamicModule("MyModule3", _
                              "MyModule3.dll")

注解

若要定义持久动态模块,需要使用或属性创建此程序集 Save RunAndSaveTo define a persistable dynamic module, this assembly needs to be created with the Save or the RunAndSave attribute.

如果希望模块包含程序集清单, name 应与程序集的名称相同 (即, AssemblyName.Name AssemblyName 用于创建动态程序集的的属性) 并且 fileName 应与保存程序集时指定的文件名相同。If you want the module to contain the assembly manifest, name should be the same as the name of the assembly (that is, the AssemblyName.Name property of the AssemblyName used to create the dynamic assembly) and fileName should be the same as the filename you specify when you save the assembly.

在只有一个模块的程序集中,该模块应包含程序集清单。In an assembly with only one module, that module should contain the assembly manifest.

备注

若要在调试动态模块时取消优化,请在 DebuggableAttribute 调用之前将特性应用于动态程序集 DefineDynamicModuleTo suppress optimizations when debugging dynamic modules, apply the DebuggableAttribute attribute to the dynamic assembly before calling DefineDynamicModule. 使用标志创建的一个实例 DebuggableAttribute DisableOptimizations ,并使用方法应用它 SetCustomAttributeCreate an instance of DebuggableAttribute with the DisableOptimizations flag and apply it using the SetCustomAttribute method. 特性必须应用于动态程序集。The attribute must be applied to the dynamic assembly. 如果应用于模块,则它不起作用。It has no effect if applied to the module.

备注

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

适用于

DefineDynamicModule(String, String, Boolean)

定义一个持久的动态模块,指定模块名称、模块将保存到的文件的名称,并指定是否使用默认符号编写器发出符号信息。Defines a persistable dynamic module, specifying the module name, the name of the file to which the module will be saved, and whether symbol information should be emitted using the default symbol writer.

public:
 System::Reflection::Emit::ModuleBuilder ^ DefineDynamicModule(System::String ^ name, System::String ^ fileName, bool emitSymbolInfo);
public System.Reflection.Emit.ModuleBuilder DefineDynamicModule (string name, string fileName, bool emitSymbolInfo);
member this.DefineDynamicModule : string * string * bool -> System.Reflection.Emit.ModuleBuilder
Public Function DefineDynamicModule (name As String, fileName As String, emitSymbolInfo As Boolean) As ModuleBuilder

参数

name
String

动态模块的名称。The name of the dynamic module.

fileName
String

动态模块应保存到的文件的名称。The name of the file to which the dynamic module should be saved.

emitSymbolInfo
Boolean

如果为 true,则将使用默认符号编写器写入符号化信息。If true, symbolic information is written using the default symbol writer.

返回

ModuleBuilder

ModuleBuilder 对象,它表示定义的动态模块。A ModuleBuilder object representing the defined dynamic module.

例外

namefileNamenullname or fileName is null.

namefileName 的长度为零。The length of name or fileName is zero.

- 或 --or- name 的长度超过系统定义的最大长度。The length of name is greater than the system-defined maximum length.

- 或 --or- fileName 包含路径说明(例如目录组件)。fileName contains a path specification (a directory component, for example).

- 或 --or- 与属于此程序集的另一个文件的名称发生冲突。There is a conflict with the name of another file that belongs to this assembly.

此程序集之前已经保存过。This assembly has been previously saved.

此程序集已在具有 Run 属性的动态程序集上调用过。This assembly was called on a dynamic assembly with the Run attribute.

无法加载默认符号编写器的程序集。The assembly for default symbol writer cannot be loaded.

- 或 --or-

找不到实现默认符号编写器接口的类型。The type that implements the default symbol writer interface cannot be found.

调用方没有所要求的权限。The caller does not have the required permission.

示例

下面的代码示例演示了如何使用发出符号的方式创建一个持久的动态模块 DefineDynamicModuleThe code example below demonstrates how to create a persistent dynamic module with symbol emission using DefineDynamicModule.

AppDomain^ myAppDomain = Thread::GetDomain();
AssemblyName^ myAsmName = gcnew AssemblyName;
myAsmName->Name = "MyAssembly";
AssemblyBuilder^ myAsmBuilder = myAppDomain->DefineDynamicAssembly(
   myAsmName, AssemblyBuilderAccess::Run );

// Create a dynamic module that can be saved as the specified DLL name. By
// specifying the third parameter as true, we can allow the emission of symbol info.
ModuleBuilder^ myModuleBuilder = myAsmBuilder->DefineDynamicModule(
   "MyModule4", "MyModule4.dll", true );
AppDomain myAppDomain = Thread.GetDomain();
AssemblyName myAsmName = new AssemblyName();
myAsmName.Name = "MyAssembly";
AssemblyBuilder myAsmBuilder = myAppDomain.DefineDynamicAssembly(
                     myAsmName,
                     AssemblyBuilderAccess.Run);
// Create a dynamic module that can be saved as the specified DLL name. By
// specifying the third parameter as true, we can allow the emission of symbol info.
ModuleBuilder myModuleBuilder = myAsmBuilder.DefineDynamicModule("MyModule4",
                                 "MyModule4.dll",
                                  true);
Dim myAppDomain As AppDomain = Thread.GetDomain()
Dim myAsmName As New AssemblyName()
myAsmName.Name = "MyAssembly"
Dim myAsmBuilder As AssemblyBuilder = myAppDomain.DefineDynamicAssembly(myAsmName, _
                      AssemblyBuilderAccess.Run)
' Create a dynamic module that can be saved as the specified DLL name. By
' specifying the third parameter as true, we can allow the emission of symbol info.
Dim myModuleBuilder As ModuleBuilder = myAsmBuilder.DefineDynamicModule("MyModule4", _
                              "MyModule4.dll", _
                              True)

注解

若要定义持久动态模块,需要使用或属性创建此程序集 Save RunAndSaveTo define a persistable dynamic module, this assembly needs to be created with the Save or the RunAndSave attribute.

如果希望模块包含程序集清单, name 应与程序集的名称相同 (即, AssemblyName.Name AssemblyName 用于创建动态程序集的的属性) 并且 fileName 应与保存程序集时指定的文件名相同。If you want the module to contain the assembly manifest, name should be the same as the name of the assembly (that is, the AssemblyName.Name property of the AssemblyName used to create the dynamic assembly) and fileName should be the same as the filename you specify when you save the assembly.

在只有一个模块的程序集中,该模块应包含程序集清单。In an assembly with only one module, that module should contain the assembly manifest.

备注

若要在调试动态模块时取消优化,请在 DebuggableAttribute 调用之前将特性应用于动态程序集 DefineDynamicModuleTo suppress optimizations when debugging dynamic modules, apply the DebuggableAttribute attribute to the dynamic assembly before calling DefineDynamicModule. 使用标志创建的一个实例 DebuggableAttribute DisableOptimizations ,并使用方法应用它 SetCustomAttributeCreate an instance of DebuggableAttribute with the DisableOptimizations flag and apply it using the SetCustomAttribute method. 特性必须应用于动态程序集。The attribute must be applied to the dynamic assembly. 如果应用于模块,则它不起作用。It has no effect if applied to the module.

备注

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

适用于