ModuleBuilder.DefineDocument 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
重载
DefineDocument(String, Guid) |
定义源的文档。 |
DefineDocument(String, Guid, Guid, Guid) |
定义源的文档。 |
DefineDocument(String, Guid)
定义源的文档。
public System.Diagnostics.SymbolStore.ISymbolDocumentWriter DefineDocument (string url, Guid language = default);
member this.DefineDocument : string * Guid -> System.Diagnostics.SymbolStore.ISymbolDocumentWriter
Public Function DefineDocument (url As String, Optional language As Guid = Nothing) As ISymbolDocumentWriter
参数
- url
- String
文档的 URL。
- language
- Guid
标识文档语言的 GUID。 这是可选的。
返回
定义的文档。
例外
url
null
。
此方法在不是持久化模块的动态模块上调用。
适用于
DefineDocument(String, Guid, Guid, Guid)
定义源的文档。
public:
System::Diagnostics::SymbolStore::ISymbolDocumentWriter ^ DefineDocument(System::String ^ url, Guid language, Guid languageVendor, Guid documentType);
public System.Diagnostics.SymbolStore.ISymbolDocumentWriter DefineDocument (string url, Guid language, Guid languageVendor, Guid documentType);
member this.DefineDocument : string * Guid * Guid * Guid -> System.Diagnostics.SymbolStore.ISymbolDocumentWriter
Public Function DefineDocument (url As String, language As Guid, languageVendor As Guid, documentType As Guid) As ISymbolDocumentWriter
参数
- url
- String
文档的 URL。
返回
定义的文档。
例外
url
null
。 这是与早期版本的 .NET Framework 的更改。
此方法在不是调试模块的动态模块上调用。
示例
下面的代码示例演示如何使用 DefineDocument
将外部符号文档(在本例中为原始 IL 文件)附加到动态模块。
using namespace System;
using namespace System::Reflection;
using namespace System::Reflection::Emit;
using namespace System::Resources;
using namespace System::Diagnostics::SymbolStore;
public ref class CodeGenerator
{
private:
ModuleBuilder^ myModuleBuilder;
AssemblyBuilder^ myAssemblyBuilder;
public:
CodeGenerator()
{
// Get the current application domain for the current thread.
AppDomain^ currentDomain = AppDomain::CurrentDomain;
AssemblyName^ myAssemblyName = gcnew AssemblyName;
myAssemblyName->Name = "TempAssembly";
// Define a dynamic assembly in the current domain.
myAssemblyBuilder = currentDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::RunAndSave );
// Define a dynamic module in S"TempAssembly" assembly.
myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "TempModule", "Resource.mod", true );
// Define a document for source.on 'TempModule' module.
ISymbolDocumentWriter^ myDocument = myModuleBuilder->DefineDocument( "RTAsm.il", SymDocumentType::Text, SymLanguageType::ILAssembly, SymLanguageVendor::Microsoft );
Console::WriteLine( "The object representing the defined document is: {0}", myDocument );
}
};
int main()
{
CodeGenerator^ myGenerator = gcnew CodeGenerator;
}
using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Resources;
using System.Diagnostics.SymbolStore;
namespace ILGenServer
{
public class CodeGenerator
{
ModuleBuilder myModuleBuilder ;
AssemblyBuilder myAssemblyBuilder ;
public CodeGenerator()
{
// Get the current application domain for the current thread.
AppDomain currentDomain = AppDomain.CurrentDomain;
AssemblyName myAssemblyName = new AssemblyName();
myAssemblyName.Name = "TempAssembly";
// Define a dynamic assembly in the current domain.
myAssemblyBuilder =
currentDomain.DefineDynamicAssembly
(myAssemblyName, AssemblyBuilderAccess.RunAndSave);
// Define a dynamic module in "TempAssembly" assembly.
myModuleBuilder =
myAssemblyBuilder.DefineDynamicModule("TempModule","Resource.mod",true);
// Define a document for source.on 'TempModule' module.
ISymbolDocumentWriter myDocument =
myModuleBuilder.DefineDocument("RTAsm.il", SymDocumentType.Text,
SymLanguageType.ILAssembly,SymLanguageVendor.Microsoft);
Console.WriteLine("The object representing the defined document is:"+myDocument);
}
}
public class CallerClass
{
public static void Main()
{
CodeGenerator myGenerator = new CodeGenerator();
}
}
}
Imports System.Reflection
Imports System.Reflection.Emit
Imports System.Resources
Imports System.Diagnostics.SymbolStore
Namespace ILGenServer
Public Class CodeGenerator
Private myModuleBuilder As ModuleBuilder
Private myAssemblyBuilder As AssemblyBuilder
Public Sub New()
' Get the current application domain for the current thread.
Dim currentDomain As AppDomain = AppDomain.CurrentDomain
Dim myAssemblyName As New AssemblyName()
myAssemblyName.Name = "TempAssembly"
' Define a dynamic assembly in the current domain.
myAssemblyBuilder = currentDomain.DefineDynamicAssembly(myAssemblyName, _
AssemblyBuilderAccess.RunAndSave)
' Define a dynamic module in "TempAssembly" assembly.
myModuleBuilder = myAssemblyBuilder.DefineDynamicModule("TempModule", "Resource.mod", True)
' Define a document for source.on 'TempModule' module.
Dim myDocument As ISymbolDocumentWriter = myModuleBuilder.DefineDocument("RTAsm.il", _
SymDocumentType.Text, SymLanguageType.ILAssembly, SymLanguageVendor.Microsoft)
Console.WriteLine("The object representing the defined document is:" + _
CObj(myDocument).ToString())
End Sub
End Class
Public Class CallerClass
Public Shared Sub Main()
Dim myGenerator As New CodeGenerator()
End Sub
End Class
End Namespace 'ILGenServer
注解
重要
早期版本的 .NET Framework 会在 null
url
时引发 ArgumentException 而不是 ArgumentNullException。