Export (0) Print
Expand All

ModuleBuilder.DefineDocument Method

Define a document for source.

Namespace: System.Reflection.Emit
Assembly: mscorlib (in mscorlib.dll)

public ISymbolDocumentWriter DefineDocument (
	string url,
	Guid language,
	Guid languageVendor,
	Guid documentType
)
public ISymbolDocumentWriter DefineDocument (
	String url, 
	Guid language, 
	Guid languageVendor, 
	Guid documentType
)
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.

Exception typeCondition

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.

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.

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();
      }
   }
}

import System.*;
import System.Reflection.*;
import System.Reflection.Emit.*;
import System.Resources.*;
import System.Diagnostics.SymbolStore.*;

public class CodeGenerator
{
    private ModuleBuilder myModuleBuilder;
    private AssemblyBuilder myAssemblyBuilder;

    public CodeGenerator()
    {
        // Get the current application domain for the current thread.
        AppDomain currentDomain = AppDomain.get_CurrentDomain();
        AssemblyName myAssemblyName = new AssemblyName();
        myAssemblyName.set_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);
    } //CodeGenerator 
} //CodeGenerator

public class CallerClass
 {
     public static void main(String[] args)
     {
         CodeGenerator myGenerator = new CodeGenerator();
     } //main
 } //CallerClass

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft