home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 June (DVD) / DPPRO0605DVD.iso / dotNETSDK / SETUP.EXE / netfxsd1.cab / ReadMe_xml_10________.3643236F_FC70_11D3_A536_0090278A1BB8 < prev    next >
Encoding:
Extensible Markup Language  |  2002-06-20  |  5.5 KB  |  88 lines

  1. <?xml version='1.0'?>
  2. <?xml-stylesheet type="text/xsl" href="..\..\..\readme.xsl"?>
  3.  
  4. <sample>
  5. <title>Reflection-Emit Sample</title>
  6. <title-short>ReflectionEmit</title-short>
  7. <overview>
  8. This sample demonstrates how to use reflection-emit. Reflection-emit is a runtime feature that allows code to create dynamic assemblies, modules and types. These types can be created for the purpose of instantiating them dynamically and using them, or reflection-emit can be used to generate an assembly and persist it to disk as an EXE or DLL. This sample consists of two executables. The first executable, EmitAssembly.exe, will generate a dynamic type, and test it, or it will generate a dynamic type and persist it to disk as a DLL. The second executable, TestEmittedAssembly.exe, simply tests the assembly dynamically emitted by the EmitAssembly.exe. The type emitted by EmitAssembly.exe is a simple class called "HelloWorld" whose constructor takes a single string parameter. The type also implements a GetGreeting() method which returns the string passed to the instance constructor.
  9. </overview>
  10. <subdirectory>Technologies\Reflection\ReflectionEmit</subdirectory>
  11. <buildsteps>
  12.    <step>
  13.       Type <b>BUILD.bat</b> from the command line.
  14.       <example>
  15.          C:\Program Files\Microsoft.NET\SDK\v1.1\Samples\Technologies\Reflection\ReflectionEmit\VB>Build.bat
  16.       </example>
  17.    </step>
  18.    <step>
  19.       Note that BUILD.bat actually builds two executable files: EmitAssembly.exe and TestEmittedAssembly.exe. However, in order to build TestEmittedAssembly.exe, the compiler needs to be able to open the referenced assembly "EmmittedAssembly.dll". After building EmitAssembly.exe, the BUILD.bat file executes EmitAssembly with the command line parameter "2" indicating that the sample should emit the dynamic assembly.
  20.    </step>
  21. </buildsteps>
  22. <runsteps>
  23.    <step>
  24.       EmitAssembly accepts a command line parameter indicating which test you would like to execute.
  25.    </step>
  26.    <step>
  27.       Type <b>EmitAssembly.exe 1</b> from the command line to have the sample emit the dynamic type into its AppDomain, and test the code using static code in the sample.
  28.       <example>
  29.          C:\Program Files\Microsoft.NET\SDK\v1.1\Samples\Technologies\Reflection\ReflectionEmit\VB>EmitAssembly.exe 1
  30.       </example>
  31.    </step>   
  32.    <step>
  33.       Type <b>EmitAssembly.exe 2</b> from the command line to have the sample emit the dynamic type into an assembly and persist the assembly to disk in the form of a .DLL and a .MOD file. After doing this, you might want to run TestEmittedAssembly.exe or ILDasm.exe to test the emitted code.
  34.       <example>
  35.          C:\Program Files\Microsoft.NET\SDK\v1.1\Samples\Technologies\Reflection\ReflectionEmit\VB>TestEmittedAssembly.exe
  36.       </example>
  37.       <example>
  38.          C:\Program Files\Microsoft.NET\SDK\v1.1\Samples\Technologies\Reflection\ReflectionEmit\VB>ILDasm EmittedModule.mod
  39.       </example>
  40.    </step>   
  41.    <step>
  42.       Type <b>EmitAssembly.exe 3</b> from the command line to have the sample emit the dynamic type into an assembly and emit a second dynamic type which tests the code of the first dynamic type.
  43.    </step>   
  44. </runsteps>
  45. <technologies>
  46.    <technology name = "Reflection-Emit" keyword="T">
  47.       <class name = "AppDomain" keyword="T">
  48.       The sample uses the AppDomain type to create a dynamic assembly in the sample's AppDomain. It does this by calling DefineDynamicAssembly().
  49.       </class>
  50.       <class name = "AssemblyBuilder" keyword="T">
  51.       The AssemblyBuilder type is used to build a dynamic assembly. It can be used to create an assembly for immediate use, or a dynamic assembly can be persisted to an assembly DLL or EXE file.
  52.       </class>           
  53.       <class name = "AssemblyName" keyword="T">
  54.       This type is used to define the unique identity of an assembly. This sample uses this type in the simplest possible way by giving the dynamic assembly the text name "EmmittedAssembly".
  55.       </class>
  56.       <class name = "ModuleBuilder" keyword="T">
  57.       The module builder type is used to build a dynamic module in the dynamic assembly.
  58.       </class>
  59.       <class name = "TypeBuilder" keyword="T">
  60.       This Type-derived type is used to build a type dynamically. From it you can request instances of the FieldBuilder, ConstrutorBuilder, and MethodBuilder types. Using these types the sample generates a complete type.
  61.       </class>
  62.       <class name = "FieldBuilder" keyword="T">
  63.       The FieldBuilder type is used to create a field in a dynamic type.
  64.       </class>
  65.       <class name = "ConstructorBuilder" keyword="T">
  66.       Used to define a constructor in a dynamic type.
  67.       </class>      
  68.       <class name = "MethodBuilder" keyword="T">
  69.       Used to define a method in a dynamic type.
  70.       </class>           
  71.       <class name = "ILGenerator" keyword="T">
  72.       Both MethodBuilder and ConstructorBuilder implement a method called GetILGenerator(). These methods return an instance of the ILGenerator type which is used to dynamically generate IL-code for a type.
  73.       </class> 
  74.       <class name = "Thread" keyword="T">
  75.       The static member function GetDomain() is used to get an instance of the AppDomain type for the current thread.
  76.       </class> 
  77.    </technology>     
  78. </technologies>
  79. <keywords>
  80.    <word name="Dynamic code" keyword="T"/>   
  81.    <word name="Self-modifying" keyword="T"/>
  82.    <word name="AssemblyBuilderAccess" keyword="T"/>   
  83.    <word name="MethodAttributes" keyword="T"/>
  84. </keywords>
  85.  
  86. </sample>
  87.  
  88.