Export (0) Print
Expand All

ModuleBuilder.DefineDocument Method

Define a document for source.

[Visual Basic]
Public Function DefineDocument( _
   ByVal url As String, _
   ByVal language As Guid, _
   ByVal languageVendor As Guid, _
   ByVal documentType As Guid _
) As ISymbolDocumentWriter
[C#]
public ISymbolDocumentWriter DefineDocument(
 string url,
 Guid language,
 Guid languageVendor,
 Guid documentType
);
[C++]
public: ISymbolDocumentWriter* DefineDocument(
 String* url,
 Guid language,
 Guid languageVendor,
 Guid documentType
);
[JScript]
public function DefineDocument(
   url : String,
 language : Guid,
 languageVendor : Guid,
 documentType : Guid
) : ISymbolDocumentWriter;

Parameters

url
The URL for the document.
language
The GUID identifying the document language. This can be null.
languageVendor
The GUID identifying the document language vendor. This can be null.
documentType
The GUID identifying the document type. This can be null.

Return Value

An ISymbolDocumentWriter object representing the defined document.

Exceptions

Exception Type Condition
ArgumentNullException url is a null reference (Nothing in Visual Basic).
InvalidOperationException This method is called on a dynamic module that is not a debug module.

Example

[Visual Basic, C#, C++] The following code sample illustrates the use of DefineDocument to attach an external symbol document (in this case, a raw IL file) to a dynamic module.

[Visual Basic] 
Imports System
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 'New
   End Class 'CodeGenerator

   Public Class CallerClass

      Public Shared Sub Main()
         Dim myGenerator As New CodeGenerator()
      End Sub 'Main
   End Class 'CallerClass
End Namespace 'ILGenServer

[C#] 
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();
      }
   }
}

[C++] 
#using <mscorlib.dll>

using namespace System;
using namespace System::Reflection;
using namespace System::Reflection::Emit;
using namespace System::Resources;
using namespace System::Diagnostics::SymbolStore;

public __gc 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 = S"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(S"TempModule", S"Resource.mod", true);

      // Define a document for source.on 'TempModule' module.
      ISymbolDocumentWriter* myDocument =
         myModuleBuilder->DefineDocument(S"RTAsm.il", SymDocumentType::Text,
         SymLanguageType::ILAssembly, SymLanguageVendor::Microsoft);

      Console::WriteLine(S"The object representing the defined document is: {0}", myDocument);

   }
};

int main() {
   CodeGenerator* myGenerator = new CodeGenerator();
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

ModuleBuilder Class | ModuleBuilder Members | System.Reflection.Emit Namespace

Show:
© 2014 Microsoft