Dela via


Defining a Dynamic Assembly

Reflection emit provides many ways to create dynamic assemblies. Dynamic assemblies can be created using the various System.AppDomain.DefineDynamicAssembly methods. DefineDynamicAssembly returns an AssemblyBuilder object. DefineDynamicAssembly requires the caller to specify the AssemblyBuilderAccess enumeration value. The enumeration value specifies whether the dynamic assembly will be run only, saved only, or run and/or saved. Some of the methods require the caller to supply evidence, which is the set of information that constitutes input to security policy decisions, such as which permissions can be granted to code. Other methods require the caller to request permissions. Three kinds of permission requests exist: required, optional, and refused.

The following list identifies the various ways in which dynamic assemblies can be defined:

  • Define a named dynamic assembly.

  • Define a named dynamic assembly given the directory for saving the assembly.

  • Define a named dynamic assembly given the evidence.

  • Define a named dynamic assembly given the permission requests.

  • Define a named dynamic assembly given the evidence and the directory for saving the assembly.

  • Define a named dynamic assembly given the permission requests and the directory for saving the assembly.

  • Define a named dynamic assembly given the evidence and the permission requests.

  • Define a named dynamic assembly given the evidence, the permission requests, and the directory for saving the assembly.

  • Define a named dynamic assembly given the evidence, the permission requests, the directory for saving the assembly, and a Boolean parameter indicating whether the creation of modules, types, and members in the dynamic assembly should be synchronized.

A persistable dynamic assembly is saved using the AssemblyBuilder.Save method. The Save method specifies the name of the file to which the assembly should be written.

See Also

Other Resources

Using Reflection Emit