AssemblyBuilder.DefineDynamicModule 方法

定義

在此組件中定義動態模組。

多載

DefineDynamicModule(String)

在此組件中定義具名的暫時性動態模組。

DefineDynamicModule(String, Boolean)

定義這個組件中的具名暫時性動態模組,並指定是否應該發出符號資訊。

DefineDynamicModule(String, String)

以會儲存在指定檔案的指定名稱定義永久性動態模組。 沒有發出任何符號資訊。

DefineDynamicModule(String, String, Boolean)

定義永久性動態模組,指定模組名稱、要儲存該模組的檔案名稱,以及是否應使用預設符號寫入器發出符號資訊。

DefineDynamicModule(String)

來源:
AssemblyBuilder.cs
來源:
AssemblyBuilder.cs
來源:
AssemblyBuilder.cs

在此組件中定義具名的暫時性動態模組。

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

動態模組的名稱。

傳回

ModuleBuilder,代表定義的動態模組。

例外狀況

name 的開頭為空白字元。

-或-

name 的長度為零。

-或-

name 的長度大於系統定義的長度上限。

namenull

呼叫端沒有必要的權限。

無法載入預設符號寫入器的組件。

-或-

找不到實作預設符號寫入器介面的類型。

範例

下列程式代碼範例示範如何使用 建立暫時性動態模組 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")

備註

在元件中定義多個具有相同名稱的動態模組是錯誤的。

定義的動態模組是暫時性的。 動態模組不會儲存,即使使用 建立 RunAndSave父動態元件也一樣。

注意

若要在偵錯動態模組時隱藏優化,請在呼叫 DefineDynamicModule之前將 DebuggableAttribute 屬性套用至動態元件。 Create 具有 旗標的 DebuggableAttribute 實例,DisableOptimizations並使用 方法套SetCustomAttribute用它。 屬性必須套用至動態元件。 如果套用至模組,則不會有任何作用。

注意

從 .NET Framework 2.0 Service Pack 1 開始,此成員不再需要 ReflectionPermissionReflectionPermissionFlag.ReflectionEmit標。 (請參閱反映發出中的安全性問題.) 若要使用此功能,您的應用程式應以 .NET Framework 3.5 或更新版本為目標。

適用於

DefineDynamicModule(String, Boolean)

定義這個組件中的具名暫時性動態模組,並指定是否應該發出符號資訊。

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

動態模組的名稱。

emitSymbolInfo
Boolean

如果要發出符號資訊,則為 true,否則為 false

傳回

ModuleBuilder,代表定義的動態模組。

例外狀況

name 的開頭為空白字元。

-或-

name 的長度為零。

-或-

name 的長度大於系統定義的長度上限。

namenull

無法載入預設符號寫入器的組件。

-或-

找不到實作預設符號寫入器介面的類型。

呼叫端沒有必要的權限。

範例

下列程式代碼範例示範如何使用 來建立暫時性動態模組 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 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)

備註

在元件中定義多個具有相同名稱的動態模組是錯誤的。

動態模組不會儲存,即使使用 建立 RunAndSave父動態元件也一樣。

注意

若要在偵錯動態模組時隱藏優化,請在呼叫 DefineDynamicModule之前將 DebuggableAttribute 屬性套用至動態元件。 Create 具有 旗標的 DebuggableAttribute 實例,DisableOptimizations並使用 方法套SetCustomAttribute用它。 屬性必須套用至動態元件。 如果套用至模組,則不會有任何作用。

注意

從 .NET Framework 2.0 Service Pack 1 開始,此成員不再需要 ReflectionPermissionReflectionPermissionFlag.ReflectionEmit標。 (請參閱反映發出中的安全性問題.) 若要使用此功能,您的應用程式應以 .NET Framework 3.5 或更新版本為目標。

適用於

DefineDynamicModule(String, String)

以會儲存在指定檔案的指定名稱定義永久性動態模組。 沒有發出任何符號資訊。

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

動態模組的名稱。

fileName
String

應該儲存動態模組的檔案名稱。

傳回

ModuleBuilder 物件代表定義的動態模組。

例外狀況

namefileNamenull

namefileName 的長度為零。

-或-

name 的長度大於系統定義的長度上限。

-或-

fileName 包含路徑規格 (例如目錄元件)。

-或-

和屬於這個組件的另一個檔案名稱發生衝突。

這個組件之前已儲存過。

這個組件在具有 Run 屬性的動態組件上呼叫過。

呼叫端沒有必要的權限。

無法載入預設符號寫入器的組件。

-或-

找不到實作預設符號寫入器介面的類型。

範例

下列程式代碼範例示範如何使用 建立永續性動態模組 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")

備註

若要定義可保存的動態模組,必須使用 或 RunAndSave 屬性來建立Save此元件。

如果您想要讓模組包含元件指令清單,name應該與元件的名稱相同 (,也就是用來建立動態元件) 的 AssemblyName 屬性,AssemblyName.Name而且fileName應該與您儲存元件時指定的檔名相同。

在只有一個模組的元件中,該模組應該包含元件指令清單。

注意

若要在偵錯動態模組時隱藏優化,請在呼叫 DefineDynamicModule之前將 DebuggableAttribute 屬性套用至動態元件。 Create 具有 旗標的 DebuggableAttribute 實例,DisableOptimizations並使用 方法套SetCustomAttribute用它。 屬性必須套用至動態元件。 如果套用至模組,則不會有任何作用。

注意

從 .NET Framework 2.0 Service Pack 1 開始,此成員不再需要 ReflectionPermissionReflectionPermissionFlag.ReflectionEmit標。 (請參閱反映發出中的安全性問題.) 若要使用此功能,您的應用程式應以 .NET Framework 3.5 或更新版本為目標。

適用於

DefineDynamicModule(String, String, Boolean)

定義永久性動態模組,指定模組名稱、要儲存該模組的檔案名稱,以及是否應使用預設符號寫入器發出符號資訊。

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

動態模組的名稱。

fileName
String

應該儲存動態模組的檔案名稱。

emitSymbolInfo
Boolean

若為 true,符號資訊會使用預設符號寫入器寫入。

傳回

ModuleBuilder 物件代表定義的動態模組。

例外狀況

namefileNamenull

namefileName 的長度為零。

-或-

name 的長度大於系統定義的長度上限。

-或-

fileName 包含路徑規格 (例如目錄元件)。

-或-

和屬於這個組件的另一個檔案名稱發生衝突。

這個組件之前已儲存過。

這個組件在具有 Run 屬性的動態組件上呼叫過。

無法載入預設符號寫入器的組件。

-或-

找不到實作預設符號寫入器介面的類型。

呼叫端沒有必要的權限。

範例

下列程式代碼範例示範如何使用 來建立具有符號發出 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)

備註

若要定義可保存的動態模組,您必須使用 SaveRunAndSave 屬性來建立此元件。

如果您想要讓模組包含元件指令清單, name 應該與元件的名稱相同 (,也就是 AssemblyName.Name 用來建立動態元件的 屬性 AssemblyName) fileName ,而且應該與您儲存元件時指定的檔名相同。

在只有一個模組的元件中,該模組應該包含元件指令清單。

注意

若要在偵錯動態模組時隱藏優化,請在呼叫 DefineDynamicModule之前將 DebuggableAttribute 屬性套用至動態元件。 Create 具有旗標的 實例DebuggableAttributeDisableOptimizations並使用 方法加以套用SetCustomAttribute。 屬性必須套用至動態元件。 如果套用至模組,則不會有任何作用。

注意

從 .NET Framework 2.0 Service Pack 1 開始,此成員不再需要ReflectionPermissionReflectionPermissionFlag.ReflectionEmit標。 (請參閱反映發出中的安全性問題 ) 若要使用這項功能,您的應用程式應以 .NET Framework 3.5 或更新版本為目標。

適用於