System.Reflection.Emit.ModuleBuilder Class

Assembly: Mscorlib.dll
Namespace: System.Reflection.Emit
Summary
Defines and represents a module. Get an instance of ModuleBuilder by calling AssemblyBuilder.DefineDynamicModule.
C# Syntax:
public class ModuleBuilder : Module
Thread Safety
Reflection Emit is thread-safe when using assemblies that were created with the AppDomain.DefineDynamicAssembly method with the Boolean parameter isSynchronized set to true.
See also:
System.Reflection.Emit Namespace

System.Reflection.Emit.ModuleBuilder Member List:

Public Properties
Assembly
(inherited from System.Reflection.Module)
Read-only

See base class member description: System.Reflection.Module.Assembly


Gets the appropriate Assembly for this instance of Module.
FullyQualifiedName Read-only

Overridden:
Gets a String representing the fully-qualified name and path to this module.
Name
(inherited from System.Reflection.Module)
Read-only

See base class member description: System.Reflection.Module.Name


Gets a String representing the name of the module with the path removed.
ScopeName
(inherited from System.Reflection.Module)
Read-only

See base class member description: System.Reflection.Module.ScopeName


Gets a string representing the name of the module.
Public Methods
CreateGlobalFunctions Complete the global function definitions for this dynamic module.
DefineDocument Define a document for source.
DefineEnum Defines an enumeration type with that is a value type with a single non-static field called value__ of the specified type.
DefineGlobalMethod Overloaded:
DefineGlobalMethod(string name, MethodAttributes attributes, Type returnType, Type[] parameterTypes)

Defines a global method given its name, attributes, return type, and parameter types.
DefineGlobalMethod Overloaded:
DefineGlobalMethod(string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)

Defines a global method given its name, attributes, calling convention, return type, and parameter types.
DefineInitializedData Defines initialized data field in the .sdata section of the portable executable (PE) file.
DefinePInvokeMethod Overloaded:
DefinePInvokeMethod(string name, string dllName, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, CallingConvention nativeCallConv, CharSet nativeCharSet)

Defines a PInvoke method given its name, the name of the DLL in which the method is defined, the attributes of the method, the calling convention of the method, the return type of the method, the types of the parameters of the method, and the PInvoke flags.
DefinePInvokeMethod Overloaded:
DefinePInvokeMethod(string name, string dllName, string entryName, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, CallingConvention nativeCallConv, CharSet nativeCharSet)

Defines a PInvoke method given its name, the name of the DLL in which the method is defined, the attributes of the method, the calling convention of the method, the return type of the method, the types of the parameters of the method, and the PInvoke flags.
DefineResource Overloaded:
DefineResource(string name, string description)

Defines the named managed embedded resource to be stored in this module.
DefineResource Overloaded:
DefineResource(string name, string description, ResourceAttributes attribute)

Defines the named managed embedded resource with the given attributes that is to be stored in this module.
DefineType Overloaded:
DefineType(string name)

Constructs a TypeBuilder for a type with the specified name.
DefineType Overloaded:
DefineType(string name, TypeAttributes attr)

Constructs a TypeBuilder given the type name and the type attributes.
DefineType Overloaded:
DefineType(string name, TypeAttributes attr, Type parent)

Constructs a TypeBuilder given type name, its attributes, and the type that the defined type extends.
DefineType Overloaded:
DefineType(string name, TypeAttributes attr, Type parent, int typesize)

Constructs a TypeBuilder given the type name, the attributes, the type that the defined type extends, and the total size of the type.
DefineType Overloaded:
DefineType(string name, TypeAttributes attr, Type parent, PackingSize packsize)

Constructs a TypeBuilder given the type name, the attributes, the type that the defined type extends, and the packing size of the type.
DefineType Overloaded:
DefineType(string name, TypeAttributes attr, Type parent, Type[] interfaces)

Constructs a TypeBuilder given the type name, attributes, the type that the defined type extends, and the interfaces that the defined type implements.
DefineType Overloaded:
DefineType(string name, TypeAttributes attr, Type parent, PackingSize packingSize, int typesize)

Constructs a TypeBuilder given the type name, attributes, the type that the defined type extends, the packing size of the defined type, and the total size of the defined type.
DefineUninitializedData Defines uninitialized data field in the .sdata section of the portable executable (PE) file.
DefineUnmanagedResource Overloaded:
DefineUnmanagedResource(byte[] resource)

Defines an unmanaged embedded resource given an opaque blob of bytes.
DefineUnmanagedResource Overloaded:
DefineUnmanagedResource(string resourceFileName)

Defines an unmanaged resource given the name of Win32 resource file.
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
FindTypes
(inherited from System.Reflection.Module)
See base class member description: System.Reflection.Module.FindTypes


Returns an array of classes accepted by the given filter and filter criteria.
GetArrayMethod Returns the named method on an array class.
GetArrayMethodToken Returns the token for the named method on an array class.
GetConstructorToken Returns the token used to identify the specified constructor within this module.
GetCustomAttributes
(inherited from System.Reflection.Module)
Overloaded:
GetCustomAttributes(bool inherit)

See base class member description: System.Reflection.Module.GetCustomAttributes


Returns all custom attributes.
GetCustomAttributes
(inherited from System.Reflection.Module)
Overloaded:
GetCustomAttributes(Type attributeType, bool inherit)

See base class member description: System.Reflection.Module.GetCustomAttributes


Gets custom attributes of the specified type.
GetField
(inherited from System.Reflection.Module)
Overloaded:
GetField(string name)

See base class member description: System.Reflection.Module.GetField


Returns a field having the specified name.
GetField
(inherited from System.Reflection.Module)
Overloaded:
GetField(string name, BindingFlags bindingAttr)

See base class member description: System.Reflection.Module.GetField


Returns a field having the specified name and binding attributes.
GetFields
(inherited from System.Reflection.Module)
See base class member description: System.Reflection.Module.GetFields


Returns an array of fields implemented by a class.
GetFieldToken Returns the token used to identify the specified field within this module.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetMethod
(inherited from System.Reflection.Module)
Overloaded:
GetMethod(string name)

See base class member description: System.Reflection.Module.GetMethod


Returns a method having the specified name.
GetMethod
(inherited from System.Reflection.Module)
Overloaded:
GetMethod(string name, Type[] types)

See base class member description: System.Reflection.Module.GetMethod


Returns a method having the specified name and parameter types.
GetMethod
(inherited from System.Reflection.Module)
Overloaded:
GetMethod(string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)

See base class member description: System.Reflection.Module.GetMethod


Returns a method having the specified name, binding information, calling convention, and parameter types and modifiers.
GetMethods
(inherited from System.Reflection.Module)
See base class member description: System.Reflection.Module.GetMethods


Returns an array of all the global methods defined on the module.
GetMethodToken Returns the token used to identify the specified method within this module.
GetObjectData
(inherited from System.Reflection.Module)
See base class member description: System.Reflection.Module.GetObjectData


Provides an ISerializable implementation for serialized objects.
GetSignatureToken Overloaded:
GetSignatureToken(SignatureHelper sigHelper)

Defines a signature token using the given SignatureHelper object.
GetSignatureToken Overloaded:
GetSignatureToken(byte[] sigBytes, int sigLength)

Defines a signature token specified by the character array and signature length.
GetStringConstant Returns the token of the given string in the module's constant pool.
GetSymWriter Returns the symbol writer associated with this dynamic module.
GetType
(inherited from System.Object)
Overloaded:
GetType()

See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
GetType Overloaded:
GetType(string className)

Overridden:
Gets the named type defined in the module.
GetType Overloaded:
GetType(string className, bool ignoreCase)

Overridden:
Gets the named type defined in the module optionally ignoring the case of the type name.
GetType Overloaded:
GetType(string className, bool throwOnError, bool ignoreCase)

Overridden:
Gets the named type defined in the module optionally ignoring the case of the type name. Optionally throws an exception if the type is not found.
GetTypes Overridden:
Returns all the classes defined within this module.
GetTypeToken Overloaded:
GetTypeToken(string name)

Returns the token used to identify the type given its name.
GetTypeToken Overloaded:
GetTypeToken(Type type)

Returns the token used to identify the specified type within this module.
IsDefined
(inherited from System.Reflection.Module)
See base class member description: System.Reflection.Module.IsDefined


Determines if the specified attributeType is defined on this module.
IsResource
(inherited from System.Reflection.Module)
See base class member description: System.Reflection.Module.IsResource


Gets a value indicating whether the object is a resource.
IsTransient Checks if this dynamic module is transient.
SetCustomAttribute Overloaded:
SetCustomAttribute(CustomAttributeBuilder customBuilder)

Set a custom attribute using a custom attribute builder.
SetCustomAttribute Overloaded:
SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)

Set a custom attribute using a specified custom attribute blob.
SetSymCustomAttribute Sets the custom attribute that is stored with the symbolic information.
SetUserEntryPoint Sets the user entry point.
ToString
(inherited from System.Reflection.Module)
See base class member description: System.Reflection.Module.ToString


Returns the name of the module.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
GetMethodImpl
(inherited from System.Reflection.Module)
See base class member description: System.Reflection.Module.GetMethodImpl


Returns the method implementation in accordance with the specified criteria.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Reflection.Emit.ModuleBuilder Member Details

Property: Assembly (read-only)
Inherited
See base class member description: System.Reflection.Module.Assembly

Summary
Gets the appropriate Assembly for this instance of Module.
C# Syntax:
public Assembly Assembly {get;}

Return to top


Overridden Property: FullyQualifiedName (read-only)
Summary
Gets a String representing the fully-qualified name and path to this module.
C# Syntax:
public override string FullyQualifiedName {get;}
Remarks
To get the name without the path, use Name.

Note The case of a module name is platform dependent.
.NET Framework Security:
FileIOPermission Accesses information in the path. Associated enumeration: FileIOPermissionAccess.PathDiscovery.

Return to top


Property: Name (read-only)
Inherited
See base class member description: System.Reflection.Module.Name

Summary
Gets a String representing the name of the module with the path removed.
C# Syntax:
public string Name {get;}
Remarks
Name is a platform-dependent string.

To get the name and the path, use Module.FullyQualifiedName.

Example
This example shows the effect of the ScopeName, FullyQualifiedName, and Name properties.
using System.Reflection;
using System;
 
 public class Simple
 {
    public static void Main ()
    {
         Module mod = Assembly.GetExecutingAssembly().GetModules () [0];
         Console.WriteLine ("Module Name is " + mod.Name);
         Console.WriteLine ("Module FullyQualifiedName is " + mod.FullyQualifiedName);
         Console.WriteLine ("Module ScopeName is " + mod.ScopeName);
    }
 }
 /*
 This code produces the following output:

 Module Name is modname.exe
 Module FullyQualifiedName is C:\Bin\modname.exe
 Module ScopeName is modname.exe
 */

    

Return to top


Property: ScopeName (read-only)
Inherited
See base class member description: System.Reflection.Module.ScopeName

Summary
Gets a string representing the name of the module.
C# Syntax:
public string ScopeName {get;}
Remarks
The ScopeName property is not used by the common language runtime, but you can use it to store any string you want in the property when you emit a module using the metadata APIs. Reflection itself does not allow you to set the ScopeName property.
Example
This example shows the effect of the ScopeName, FullyQualifiedName, and Name properties.
 using System.Reflection;
 using System;
 
 public class Simple
 {
    public static void Main ()
    {
         Module mod = Assembly.GetExecutingAssembly().GetModules () [0];
         Console.WriteLine ("Module Name is "
            + mod.Name);
         Console.WriteLine ("Module FullyQualifiedName is "
            + mod.FullyQualifiedName);
         Console.WriteLine ("Module ScopeName is "
            + mod.ScopeName);
    }
 }
 /*
 Produces this output:
 Module Name is modname.exe
 Module FullyQualifiedName is C:\Bin\modname.exe
 Module ScopeName is modname.exe
 */

    

Return to top


Method: CreateGlobalFunctions()
Summary
Complete the global function definitions for this dynamic module.
C# Syntax:
public void CreateGlobalFunctions();
Exceptions
Exception Type Condition
InvalidOperationException This method was called previously.
Remarks
This method should be called when the user is done with defining all of the global functions within this dynamic module. After calling this function, no more new global functions or new global data are allowed.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit

Return to top


Method: DefineDocument(
   string url,
   Guid language,
   Guid languageVendor,
   Guid documentType
)
Summary
Define a document for source.
C# Syntax:
public ISymbolDocumentWriter DefineDocument(
   string url,
   Guid language,
   Guid languageVendor,
   Guid documentType
);
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 null.
InvalidOperationException This method is called on a dynamic module that is not a debug module.

Return to top


Method: DefineEnum(
   string name,
   TypeAttributes visibility,
   Type underlyingType
)
Summary
Defines an enumeration type with that is a value type with a single non-static field called value__ of the specified type.
C# Syntax:
public EnumBuilder DefineEnum(
   string name,
   TypeAttributes visibility,
   Type underlyingType
);
Parameters:

name

The full path of the enumeration type.name cannot contain embedded nulls.

visibility

The type attributes for the enumeration. The attributes are any bits defined by TypeAttributes.VisibilityMask.

underlyingType

The underlying type for the enumeration.

Return Value:
Returns the defined enumeration.
Exceptions
Exception Type Condition
ArgumentException Attributes other than visibility attributes are provided.

-or-

An enum with the given name exists in the parent assembly of this module.

-or-

When the visibility attributes are incorrect for the scope of the enum. For example, if TypeAttributes.NestedPublic is specified as the visibility but the enum is not a nested type.

ArgumentNullException name is null.
Remarks
The defined enum is a derived class of Enum. The defined field has FieldAttributes.Private and FieldAttributes.SpecialName set.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit

Return to top


Overloaded Method: DefineGlobalMethod(
   string name,
   MethodAttributes attributes,
   Type returnType,
   Type[] parameterTypes
)
Summary
Defines a global method given its name, attributes, return type, and parameter types.
C# Syntax:
public MethodBuilder DefineGlobalMethod(
   string name,
   MethodAttributes attributes,
   Type returnType,
   Type[] parameterTypes
);
Parameters:

name

The name of the method.name cannot contain embedded nulls.

attributes

The attributes of the method.

returnType

The return type of the method.

parameterTypes

The types of the method's parameters.

Return Value:
Returns the defined global method.
Exceptions
Exception Type Condition
ArgumentException The method is not static.

-or-

The length of name is zero

ArgumentNullException name is null.
InvalidOperationException ModuleBuilder.CreateGlobalFunctions has been previously called.
Remarks


Notes to implementors: The global method that this method defines is not usable until you call ModuleBuilder.CreateGlobalFunctions.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit

Return to top


Overloaded Method: DefineGlobalMethod(
   string name,
   MethodAttributes attributes,
   CallingConventions callingConvention,
   Type returnType,
   Type[] parameterTypes
)
Summary
Defines a global method given its name, attributes, calling convention, return type, and parameter types.
C# Syntax:
public MethodBuilder DefineGlobalMethod(
   string name,
   MethodAttributes attributes,
   CallingConventions callingConvention,
   Type returnType,
   Type[] parameterTypes
);
Parameters:

name

The name of the method.name cannot contain embedded nulls.

attributes

The attributes of the method.

callingConvention

The calling convention for the method.

returnType

The return type of the method.

parameterTypes

The types of the method's parameters.

Return Value:
Returns the defined global method.
Exceptions
Exception Type Condition
ArgumentException The method is not static.
ArgumentNullException name is null.
InvalidOperationException ModuleBuilder.CreateGlobalFunctions has been previously called.
Remarks


Notes to implementors: You cannot use the global method that this method defines until you call ModuleBuilder.CreateGlobalFunctions.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit

Return to top


Method: DefineInitializedData(
   string name,
   byte[] data,
   FieldAttributes attributes
)
Summary
Defines initialized data field in the .sdata section of the portable executable (PE) file.
C# Syntax:
public FieldBuilder DefineInitializedData(
   string name,
   byte[] data,
   FieldAttributes attributes
);
Parameters:

name

The name used to refer to the data.name cannot contain embedded nulls.

data

The blob of data.

attributes

The attributes for the field. The default is Static.

Return Value:
A field to reference the data.
Exceptions
Exception Type Condition
ArgumentNullException name is null.
InvalidOperationException ModuleBuilder.CreateGlobalFunctions has been previously called.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit

Return to top


Overloaded Method: DefinePInvokeMethod(
   string name,
   string dllName,
   MethodAttributes attributes,
   CallingConventions callingConvention,
   Type returnType,
   Type[] parameterTypes,
   CallingConvention nativeCallConv,
   CharSet nativeCharSet
)
Summary
Defines a PInvoke method given its name, the name of the DLL in which the method is defined, the attributes of the method, the calling convention of the method, the return type of the method, the types of the parameters of the method, and the PInvoke flags.
C# Syntax:
public MethodBuilder DefinePInvokeMethod(
   string name,
   string dllName,
   MethodAttributes attributes,
   CallingConventions callingConvention,
   Type returnType,
   Type[] parameterTypes,
   CallingConvention nativeCallConv,
   CharSet nativeCharSet
);
Parameters:

name

The name of the PInvoke method.name cannot contain embedded nulls.

dllName

The name of the DLL in which the PInvoke method is defined.

attributes

The attributes of the method.

callingConvention

The method's calling convention.

returnType

The method's return type.

parameterTypes

The types of the method's parameters.

nativeCallConv

The native calling convention.

nativeCharSet

The method's native character set.

Return Value:
The defined PInvoke method.
Exceptions
Exception Type Condition
ArgumentException The method is not static or if the containing type is an interface.

-or-

The method is abstract.

-or-

The method was previously defined.

ArgumentNullException name or dllName is null.
InvalidOperationException The containing type has been previously created using TypeBuilder.CreateType
Remarks
Some DLL import attributes (see the description of System.Runtime.InteropServices.DllImportAttribute) cannot be specified as arguments to this method. Such attributes should be set by emitting a custom attribute for the method. For example, the DLL import attribute PreserveSig is set by emitting a custom attribute.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit

Return to top


Overloaded Method: DefinePInvokeMethod(
   string name,
   string dllName,
   string entryName,
   MethodAttributes attributes,
   CallingConventions callingConvention,
   Type returnType,
   Type[] parameterTypes,
   CallingConvention nativeCallConv,
   CharSet nativeCharSet
)
Summary
Defines a PInvoke method given its name, the name of the DLL in which the method is defined, the attributes of the method, the calling convention of the method, the return type of the method, the types of the parameters of the method, and the PInvoke flags.
C# Syntax:
public MethodBuilder DefinePInvokeMethod(
   string name,
   string dllName,
   string entryName,
   MethodAttributes attributes,
   CallingConventions callingConvention,
   Type returnType,
   Type[] parameterTypes,
   CallingConvention nativeCallConv,
   CharSet nativeCharSet
);
Parameters:

name

The name of the PInvoke method.name cannot contain embedded nulls.

dllName

The name of the DLL in which the PInvoke method is defined.

entryName

The name of the entry point in the DLL.

attributes

The attributes of the method.

callingConvention

The method's calling convention.

returnType

The method's return type.

parameterTypes

The types of the method's parameters.

nativeCallConv

The native calling convention.

nativeCharSet

The method's native character set.

Return Value:
The defined PInvoke method.
Exceptions
Exception Type Condition
ArgumentException The method is not static or if the containing type is an interface or if the method is abstract of if the method was previously defined.
ArgumentNullException name or dllName is null.
InvalidOperationException The containing type has been previously created using TypeBuilder.CreateType
Remarks
Some DLL import attributes (see the description of System.Runtime.InteropServices.DllImportAttribute) cannot be specified as arguments to this method. Such attributes should be set by emitting a custom attribute for the method. For example, the DLL import attribute PreserveSig is set by emitting a custom attribute.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit

Return to top


Overloaded Method: DefineResource(
   string name,
   string description
)
Summary
Defines the named managed embedded resource to be stored in this module.
C# Syntax:
public IResourceWriter DefineResource(
   string name,
   string description
);
Parameters:

name

The name of the resource.name cannot contain embedded nulls.

description

The description of the resource.

Return Value:
Returns a resource writer for the defined resource.
Exceptions
Exception Type Condition
ArgumentException Length of name is zero.
ArgumentNullException name is null.
InvalidOperationException This module is transient.

-or-

The containing assembly is not persistable.

Remarks
The caller must not call the ResourceWriter.Generate() and ResourceWriter.Close() methods since these methods are called by ModuleBuilder.Save when the dynamic assembly is written to disk.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit

Return to top


Overloaded Method: DefineResource(
   string name,
   string description,
   ResourceAttributes attribute
)
Summary
Defines the named managed embedded resource with the given attributes that is to be stored in this module.
C# Syntax:
public IResourceWriter DefineResource(
   string name,
   string description,
   ResourceAttributes attribute
);
Parameters:

name

The name of the resource.name cannot contain embedded nulls.

description

The description of the resource.

attribute

The resource attributes.

Return Value:
Returns a resource writer for the defined resource.
Exceptions
Exception Type Condition
ArgumentException Length of name is zero.
ArgumentNullException name is null.
InvalidOperationException This module is transient.

-or-

The containing assembly is not persistable.

Remarks
The caller must not call the ResourceWriter.Generate() and ResourceWriter.Close() methods since these methods are called by ModuleBuilder.Save when the dynamic assembly is written to disk.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit

Return to top


Overloaded Method: DefineType(
   string name
)
Summary
Constructs a TypeBuilder for a type with the specified name.
C# Syntax:
public TypeBuilder DefineType(
   string name
);
Parameters:

name

The full path of the type.name cannot contain embedded nulls.

Return Value:
Returns the created TypeBuilder.
Exceptions
Exception Type Condition
ArgumentException A type with the given name exists in the parent assembly of this module.
ArgumentNullException name is null.
Remarks
Type names must be unique within an assembly. You cannot have two types with the same name in two different modules of an assembly.
Example
The following example defines a type in a dynamic assembly, completes the type, and saves the assembly.
 AssemblyName asmname = new AssemblyName();
 asmname.Name = "assemfilename.exe";        
 AssemblyBuilder asmbuild = System.Threading.Thread.GetDomain().
             DefineDynamicAssembly(asmname, AssemblyBuilderAccess.RunAndSave);
 ModuleBuilder modbuild = asmbuild.DefineDynamicModule( "modulename",
    "assemfilename.exe" );
 TypeBuilder typebuild1 = modbuild.DefineType( "typename" );
 typebuild1.CreateType();
 asmbuild.Save( "assemfilename.exe" );

    
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit

Return to top


Overloaded Method: DefineType(
   string name,
   TypeAttributes attr
)
Summary
Constructs a TypeBuilder given the type name and the type attributes.
C# Syntax:
public TypeBuilder DefineType(
   string name,
   TypeAttributes attr
);
Parameters:

name

The full path of the type.name cannot contain embedded nulls.

attr

The attributes of the defined type.

Return Value:
Returns a TypeBuilder created with all of the requested attributes.
Exceptions
Exception Type Condition
ArgumentException A type with the given name exists in the parent assembly of this module.
ArgumentNullException name is null.
Remarks
Type names must be unique within an assembly. You cannot have two types with the same name in two different modules of an assembly.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit

Return to top


Overloaded Method: DefineType(
   string name,
   TypeAttributes attr,
   Type parent
)
Summary
Constructs a TypeBuilder given type name, its attributes, and the type that the defined type extends.
C# Syntax:
public TypeBuilder DefineType(
   string name,
   TypeAttributes attr,
   Type parent
);
Parameters:

name

The full path of the type.name cannot contain embedded nulls.

attr

The attribute to be associated with the type.

parent

The Type that the defined type extends.

Return Value:
Returns a TypeBuilder created with all of the requested attributes.
Exceptions
Exception Type Condition
ArgumentException A type with the given name exists in the parent assembly of this module.
ArgumentNullException name is null.
Remarks
Type names must be unique within an assembly. You cannot have two types with the same name in two different modules of an assembly.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit

Return to top


Overloaded Method: DefineType(
   string name,
   TypeAttributes attr,
   Type parent,
   int typesize
)
Summary
Constructs a TypeBuilder given the type name, the attributes, the type that the defined type extends, and the total size of the type.
C# Syntax:
public TypeBuilder DefineType(
   string name,
   TypeAttributes attr,
   Type parent,
   int typesize
);
Parameters:

name

The full path of the type.name cannot contain embedded nulls.

attr

The attributes of the defined type.

parent

The Type that the defined type extends.

typesize

The total size of the type.

Return Value:
Returns a TypeBuilder object.
Exceptions
Exception Type Condition
ArgumentException A type with the given name exists in the parent assembly of this module.
ArgumentNullException name is null.
Remarks
Type names must be unique within an assembly. It is forbidden to have two types with the same name in two different modules of an assembly.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit

Return to top


Overloaded Method: DefineType(
   string name,
   TypeAttributes attr,
   Type parent,
   PackingSize packsize
)
Summary
Constructs a TypeBuilder given the type name, the attributes, the type that the defined type extends, and the packing size of the type.
C# Syntax:
public TypeBuilder DefineType(
   string name,
   TypeAttributes attr,
   Type parent,
   PackingSize packsize
);
Parameters:

name

The full path of the type.name cannot contain embedded nulls.

attr

The attributes of the defined type.

parent

The Type that the defined type extends.

packsize

The packing size of the type.

Return Value:
Returns a TypeBuilder object.
Exceptions
Exception Type Condition
ArgumentException A type with the given name exists in the parent assembly of this module.
ArgumentNullException name is null.
Remarks
Type names must be unique within an assembly. You cannot have two types with the same name in two different modules of an assembly.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit

Return to top


Overloaded Method: DefineType(
   string name,
   TypeAttributes attr,
   Type parent,
   Type[] interfaces
)
Summary
Constructs a TypeBuilder given the type name, attributes, the type that the defined type extends, and the interfaces that the defined type implements.
C# Syntax:
public TypeBuilder DefineType(
   string name,
   TypeAttributes attr,
   Type parent,
   Type[] interfaces
);
Parameters:

name

The full path of the type.name cannot contain embedded nulls.

attr

The attributes to be associated with the type.

parent

The type that the defined type extends.

interfaces

The list of interfaces that the type implements.

Return Value:
Returns a TypeBuilder created with all of the requested attributes.
Exceptions
Exception Type Condition
ArgumentException A type with the given name exists in the parent assembly of this module.
ArgumentNullException name is null.
Remarks
Type names must be unique within an assembly. You cannot have two types with the same name in two different modules of an assembly.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit

Return to top


Overloaded Method: DefineType(
   string name,
   TypeAttributes attr,
   Type parent,
   PackingSize packingSize,
   int typesize
)
Summary
Constructs a TypeBuilder given the type name, attributes, the type that the defined type extends, the packing size of the defined type, and the total size of the defined type.
C# Syntax:
public TypeBuilder DefineType(
   string name,
   TypeAttributes attr,
   Type parent,
   PackingSize packingSize,
   int typesize
);
Parameters:

name

The full path of the type.name cannot contain embedded nulls.

attr

The attributes of the defined type.

parent

The type that the defined type extends.

packingSize

The packing size of the type.

typesize

The total size of the type.

Return Value:
Returns a TypeBuilder created with all of the requested attributes.
Exceptions
Exception Type Condition
ArgumentException A type with the given name exists in the parent assembly of this module
ArgumentNullException name is null.
Remarks
Type names must be unique within an assembly. You cannot have two types with the same name in two different modules of an assembly.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit

Return to top


Method: DefineUninitializedData(
   string name,
   int size,
   FieldAttributes attributes
)
Summary
Defines uninitialized data field in the .sdata section of the portable executable (PE) file.
C# Syntax:
public FieldBuilder DefineUninitializedData(
   string name,
   int size,
   FieldAttributes attributes
);
Parameters:

name

The name used to refer to the data.name cannot contain embedded nulls.

size

The blob of data.

attributes

The attributes for the field.

Return Value:
A field to reference the data.
Exceptions
Exception Type Condition
ArgumentNullException name is null.
InvalidOperationException ModuleBuilder.CreateGlobalFunctions has been previously called.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit

Return to top


Overloaded Method: DefineUnmanagedResource(
   byte[] resource
)
Summary
Defines an unmanaged embedded resource given an opaque blob of bytes.
C# Syntax:
public void DefineUnmanagedResource(
   byte[] resource
);
Parameters:

resource

An opaque blob that represents an unmanaged resource

Exceptions
Exception Type Condition
ArgumentException An unmanaged resource has already been defined in the module's assembly.
ArgumentNullException resource is null.
Remarks
An assembly can be associated with only one unmanaged resource. This means that calling DefineVersionInfoResource or DefineUnmanagedResource after either one of the methods was called previously will result in the System.ArgumentException being throw. Multiple unmanaged resources need to be merged with a tool such as the Microsoft ResMerge utility (not supplied with the common language runtime).
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit

Return to top


Overloaded Method: DefineUnmanagedResource(
   string resourceFileName
)
Summary
Defines an unmanaged resource given the name of Win32 resource file.
C# Syntax:
public void DefineUnmanagedResource(
   string resourceFileName
);
Parameters:

resourceFileName

The name of the unmanaged resource file

Exceptions
Exception Type Condition
ArgumentException An unmanaged resource has already been defined in the module's assembly.

-or-

resourceFileName is the empty string ("").

ArgumentNullException resource is null.
FileNotFoundException resourceFileName is not found

-or-

resourceFileName is a directory

Remarks
An assembly can be associated with only one unmanaged resource. This means that calling DefineVersionInfoResource or DefineUnmanagedResource after either one of the methods was called previously will throw the System.ArgumentException. Multiple unmanaged resources need to be merged with a tool such as the Microsoft ResMerge utility (not supplied with the common language runtime).
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~ModuleBuilder();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: FindTypes(
   TypeFilter filter,
   object filterCriteria
)
Inherited
See base class member description: System.Reflection.Module.FindTypes

Summary
Returns an array of classes accepted by the given filter and filter criteria.
C# Syntax:
public virtual Type[] FindTypes(
   TypeFilter filter,
   object filterCriteria
);
Parameters:

filter

The delegate used to filter the classes.

filterCriteria

An Object used to filter the classes.

Return Value:
An array of type Type containing classes that were accepted by the filter.
Exceptions
Exception Type Condition
ReflectionTypeLoadException One or more classes in a module could not be loaded.
Remarks
ReflectionTypeLoadException is a special class load exception. The ReflectionTypeLoadException.Types property contains the array of classes that were defined in the module and were loaded. This array may contain some null values. The ReflectionTypeLoadException.LoaderExceptions property is an array of exceptions that represent the exceptions that were thrown by the class loader. The holes in the class array line up with the exceptions.

The delegate given by filter is called for each class in the module, passing along the Type object representing the class as well as the given filterCriteria. If filter returns a particular class, that class will be included in the returned array. If filter returns null, all classes are returned and filterCriteria is ignored.

FindTypes cannot be used to look up parameterized types such as arrays.

See also:
Module.FilterTypeName | Module.FilterTypeNameIgnoreCase | ReflectionTypeLoadException

Return to top


Method: GetArrayMethod(
   Type arrayClass,
   string methodName,
   CallingConventions callingConvention,
   Type returnType,
   Type[] parameterTypes
)
Summary
Returns the named method on an array class.
C# Syntax:
public MethodInfo GetArrayMethod(
   Type arrayClass,
   string methodName,
   CallingConventions callingConvention,
   Type returnType,
   Type[] parameterTypes
);
Parameters:

arrayClass

An array class.

methodName

The name of a method on the array class.

callingConvention

The method's calling convention.

returnType

The return type of the method.

parameterTypes

The types of the method's parameters.

Return Value:
The named method on an array class.
Exceptions
Exception Type Condition
ArgumentException arrayClass is not an array.
ArgumentNullException arrayClass or methodName is null.
Remarks
GetArrayMethod is useful when you have an array of a type whose definition has not been completed and you want to access methods defined on Array. For example, you might define a type and want to define a method that takes an array of the type as a parameter. In order to access the elements of the array, you will need to call methods of the Array class.

Return to top


Method: GetArrayMethodToken(
   Type arrayClass,
   string methodName,
   CallingConventions callingConvention,
   Type returnType,
   Type[] parameterTypes
)
Summary
Returns the token for the named method on an array class.
C# Syntax:
public MethodToken GetArrayMethodToken(
   Type arrayClass,
   string methodName,
   CallingConventions callingConvention,
   Type returnType,
   Type[] parameterTypes
);
Parameters:

arrayClass

The Type object for the array.

methodName

A string containing the name of the method.

callingConvention

The calling convention for the method.

returnType

The return type of the method.

parameterTypes

The types of the parameters of the method.

Return Value:
The token for the named method on an array class.
Exceptions
Exception Type Condition
ArgumentException arrayClass is not an array.

-or-

Length of methodName is zero.

ArgumentNullException arrayClass or methodName is null.
Remarks
This method is similar to ModuleBuilder.GetArrayMethod, except that it returns the token of the array method instead of the method itself.

Return to top


Method: GetConstructorToken(
   ConstructorInfo con
)
Summary
Returns the token used to identify the specified constructor within this module.
C# Syntax:
public MethodToken GetConstructorToken(
   ConstructorInfo con
);
Parameters:

con

A ConstructorInfo object representing the constructor to get a token for.

Return Value:
Returns the token used to identify the constructor represented by con within this module.
Exceptions
Exception Type Condition
ArgumentNullException con is null.

Return to top


Overloaded Method: GetCustomAttributes(
   bool inherit
)
Inherited
See base class member description: System.Reflection.Module.GetCustomAttributes

Summary
Returns all custom attributes.
C# Syntax:
public virtual object[] GetCustomAttributes(
   bool inherit
);
Parameters:

inherit

This argument is ignored for objects of this type.

Return Value:
An array of type Object containing all custom attributes.
Implements:
ICustomAttributeProvider.GetCustomAttributes

Return to top


Overloaded Method: GetCustomAttributes(
   Type attributeType,
   bool inherit
)
Inherited
See base class member description: System.Reflection.Module.GetCustomAttributes

Summary
Gets custom attributes of the specified type.
C# Syntax:
public virtual object[] GetCustomAttributes(
   Type attributeType,
   bool inherit
);
Parameters:

attributeType

The type of attribute to get.

inherit

This argument is ignored for objects of this type.

Return Value:
An array of type Object containing all custom attributes of the specified type.
Exceptions
Exception Type Condition
ArgumentNullException attributeType is null.
Implements:
ICustomAttributeProvider.GetCustomAttributes

Return to top


Overloaded Method: GetField(
   string name
)
Inherited
See base class member description: System.Reflection.Module.GetField

Summary
Returns a field having the specified name.
C# Syntax:
public FieldInfo GetField(
   string name
);
Parameters:

name

The field name.

Return Value:
A FieldInfo object having the specified name.
Exceptions
Exception Type Condition
ArgumentException The name parameter is null.

Return to top


Overloaded Method: GetField(
   string name,
   BindingFlags bindingAttr
)
Inherited
See base class member description: System.Reflection.Module.GetField

Summary
Returns a field having the specified name and binding attributes.
C# Syntax:
public FieldInfo GetField(
   string name,
   BindingFlags bindingAttr
);
Parameters:

name

The field name.

bindingAttr

One of the BindingFlags bit flags used to control the search.

Return Value:
A FieldInfo object having the specified name and binding attributes.
Exceptions
Exception Type Condition
ArgumentException The name parameter is null.
.NET Framework Security:
ReflectionPermission for returning fields that are not public. Associated enumeration: ReflectionPermissionFlag.TypeInformation

Return to top


Method: GetFields()
Inherited
See base class member description: System.Reflection.Module.GetFields

Summary
Returns an array of fields implemented by a class.
C# Syntax:
public FieldInfo[] GetFields();
Return Value:
An array of type FieldInfo containing the fields implemented by a class.

Return to top


Method: GetFieldToken(
   FieldInfo field
)
Summary
Returns the token used to identify the specified field within this module.
C# Syntax:
public FieldToken GetFieldToken(
   FieldInfo field
);
Parameters:

field

A FieldInfo object representing the field to get a token for.

Return Value:
Returns the token used to identify the field represented by con within this module.
Exceptions
Exception Type Condition
ArgumentNullException con is null.
InvalidOperationException The field is defined in a different module.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: GetMethod(
   string name
)
Inherited
See base class member description: System.Reflection.Module.GetMethod

Summary
Returns a method having the specified name.
C# Syntax:
public MethodInfo GetMethod(
   string name
);
Parameters:

name

The method name.

Return Value:
A MethodInfo object having the specified name.
Exceptions
Exception Type Condition
ArgumentNullException name is null.

Return to top


Overloaded Method: GetMethod(
   string name,
   Type[] types
)
Inherited
See base class member description: System.Reflection.Module.GetMethod

Summary
Returns a method having the specified name and parameter types.
C# Syntax:
public MethodInfo GetMethod(
   string name,
   Type[] types
);
Parameters:

name

The method name.

types

The parameter types to search for.

Return Value:
A MethodInfo object in accordance with the specified criteria.
Exceptions
Exception Type Condition
ArgumentNullException name is null, types is null, or types (i) is null.

Return to top


Overloaded Method: GetMethod(
   string name,
   BindingFlags bindingAttr,
   Binder binder,
   CallingConventions callConvention,
   Type[] types,
   ParameterModifier[] modifiers
)
Inherited
See base class member description: System.Reflection.Module.GetMethod

Summary
Returns a method having the specified name, binding information, calling convention, and parameter types and modifiers.
C# Syntax:
public MethodInfo GetMethod(
   string name,
   BindingFlags bindingAttr,
   Binder binder,
   CallingConventions callConvention,
   Type[] types,
   ParameterModifier[] modifiers
);
Parameters:

name

The method name.

bindingAttr

One of the BindingFlags bit flags used to control the search.

binder

An object that implements Binder, containing properties related to this method.

callConvention

The calling convention for the method.

types

The parameter types to search for.

modifiers

An array of parameter modifiers used to make binding work with parameter signatures in which the types have been modified.

Return Value:
A MethodInfo object in accordance with the specified criteria.
Exceptions
Exception Type Condition
ArgumentNullException name is null, types is null, or types (i) is null.
See also:
BindingFlags | CallingConventions | ParameterModifier

Return to top


Method: GetMethodImpl(
   string name,
   BindingFlags bindingAttr,
   Binder binder,
   CallingConventions callConvention,
   Type[] types,
   ParameterModifier[] modifiers
)
Inherited
See base class member description: System.Reflection.Module.GetMethodImpl

Summary
Returns the method implementation in accordance with the specified criteria.
C# Syntax:
protected virtual MethodInfo GetMethodImpl(
   string name,
   BindingFlags bindingAttr,
   Binder binder,
   CallingConventions callConvention,
   Type[] types,
   ParameterModifier[] modifiers
);
Parameters:

name

The method name.

bindingAttr

One of the BindingFlags bit flags used to control the search.

binder

An object that implements Binder, containing properties related to this method.

callConvention

The calling convention for the method.

types

The parameter types to search for.

modifiers

An array of parameter modifiers used to make binding work with parameter signatures in which the types have been modified.

Return Value:
A MethodInfo object containing implementation information as specified.
Exceptions
Exception Type Condition
AmbiguousMatchException types is null.
See also:
BindingFlags | CallingConventions | ParameterModifier

Return to top


Method: GetMethods()
Inherited
See base class member description: System.Reflection.Module.GetMethods

Summary
Returns an array of all the global methods defined on the module.
C# Syntax:
public MethodInfo[] GetMethods();
Return Value:
An array of type MethodInfo containing all the global methods defined on the module.

Return to top


Method: GetMethodToken(
   MethodInfo method
)
Summary
Returns the token used to identify the specified method within this module.
C# Syntax:
public MethodToken GetMethodToken(
   MethodInfo method
);
Parameters:

method

A MethodToken object representing the method to get a token for.

Return Value:
Returns the token used to identify the method represented by method within this module.
Exceptions
Exception Type Condition
ArgumentNullException method is null.
InvalidOperationException The declaring type for the method is not in this module.

Return to top


Method: GetObjectData(
   SerializationInfo info,
   StreamingContext context
)
Inherited
See base class member description: System.Reflection.Module.GetObjectData

Summary
Provides an ISerializable implementation for serialized objects.
C# Syntax:
public virtual void GetObjectData(
   SerializationInfo info,
   StreamingContext context
);
Parameters:

info

The information and data needed to serialize or deserialize an object.

context

The context for the serialization.

Exceptions
Exception Type Condition
ArgumentNullException info is null.
Implements:
ISerializable.GetObjectData

Return to top


Overloaded Method: GetSignatureToken(
   SignatureHelper sigHelper
)
Summary
Defines a signature token using the given SignatureHelper object.
C# Syntax:
public SignatureToken GetSignatureToken(
   SignatureHelper sigHelper
);
Parameters:

sigHelper

A reference to a SignatureHelper.

Return Value:
A SignatureToken for the defined signature.
Exceptions
Exception Type Condition
ArgumentNullException sigHelper is null.
Remarks
This will define a metadata token for the signature described by SignatureHelper.

Return to top


Overloaded Method: GetSignatureToken(
   byte[] sigBytes,
   int sigLength
)
Summary
Defines a signature token specified by the character array and signature length.
C# Syntax:
public SignatureToken GetSignatureToken(
   byte[] sigBytes,
   int sigLength
);
Parameters:

sigBytes

The signature blob.

sigLength

The length of the signature blob.

Return Value:
A SignatureToken for the defined signature.

Return to top


Method: GetStringConstant(
   string str
)
Summary
Returns the token of the given string in the module's constant pool.
C# Syntax:
public StringToken GetStringConstant(
   string str
);
Parameters:

str

The string to add to the module's constant pool.

Return Value:
Returns the StringToken of the string added to the constant pool.
Exceptions
Exception Type Condition
ArgumentNullException str is null.
Remarks
If str has already been defined, the existing token will be returned.

Return to top


Method: GetSymWriter()
Summary
Returns the symbol writer associated with this dynamic module.
C# Syntax:
public ISymbolWriter GetSymWriter();
Return Value:
Returns the symbol writer associated with this dynamic module.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit

Return to top


Overloaded Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: GetType(
   string className
)
Summary
Gets the named type defined in the module.
C# Syntax:
public override Type GetType(
   string className
);
Parameters:

className

The name of the Type to get.

Return Value:
The requested type. Returns null if the type is not found.
Exceptions
Exception Type Condition
ArgumentException Length of className is zero or if length of className is greater than 1023.
ArgumentNullException className is null.
SecurityException The requested Type is non-public and the caller does not have ReflectionPermission to reflect non-public objects outside the current assembly.
TargetInvocationException A class initializer is invoked and throws an exception.
TypeLoadException An error is encountered while loading the Type.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit

Return to top


Overloaded Method: GetType(
   string className,
   bool ignoreCase
)
Summary
Gets the named type defined in the module optionally ignoring the case of the type name.
C# Syntax:
public override Type GetType(
   string className,
   bool ignoreCase
);
Parameters:

className

The name of the Type to get.

ignoreCase

true to perform a case-insensitive search for typeName, if typeName has less than 128 characters.false to perform a case-sensitive search for typeName.true to perform a case-insensitive search for typeName, if typeName has less than 128 characters.false to perform a case-sensitive search for typeName.

Return Value:
The requested type. Returns null if the type is not found.
Exceptions
Exception Type Condition
ArgumentException Length of className is zero.

-or-

The length of className is greater than 1023.

ArgumentNullException className is null.
SecurityException The requested Type is non-public and the caller does not have ReflectionPermission to reflect non-public objects outside the current assembly.
TargetInvocationException A class initializer is invoked and throws an exception.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit

Return to top


Overloaded Method: GetType(
   string className,
   bool throwOnError,
   bool ignoreCase
)
Summary
Gets the named type defined in the module optionally ignoring the case of the type name. Optionally throws an exception if the type is not found.
C# Syntax:
public override Type GetType(
   string className,
   bool throwOnError,
   bool ignoreCase
);
Parameters:

className

The name of the Type to get.

throwOnError

true to throw a TypeLoadException if an error occurs while loading the Type.false to ignore errors while loading the Type.true to throw a TypeLoadException if an error occurs while loading the Type.false to ignore errors while loading the Type.

ignoreCase

true to perform a case-insensitive search for typeName, if typeName has less than 128 characters.false to perform a case-sensitive search for typeName.true to perform a case-insensitive search for typeName, if typeName has less than 128 characters.false to perform a case-sensitive search for typeName.

Return Value:
The requested type. Returns null if the type is not found.
Exceptions
Exception Type Condition
ArgumentException Length of className is zero.

-or-

The length of className is greater than 1023.

ArgumentNullException className is null.
SecurityException The requested Type is non-public and the caller does not have ReflectionPermission to reflect non-public objects outside the current assembly.
TargetInvocationException A class initializer is invoked and throws an exception.
TypeLoadException throwOnError is true and an error is encountered while loading the Type.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit

Return to top


Overridden Method: GetTypes()
Summary
Returns all the classes defined within this module.
C# Syntax:
public override Type[] GetTypes();
Return Value:
An array of type Type containing classes defined within the module that is reflected by this instance.
Exceptions
Exception Type Condition
ReflectionTypeLoadException One or more classes in a module could not be loaded.
SecurityException The caller does not have the required permission.
Remarks
ReflectionTypeLoadException is a special class load exception. The ReflectionTypeLoadException.Types property contains the array of classes that were defined in the module and loaded. This array can contain some null values. The ReflectionTypeLoadException.LoaderExceptions property is an array of exceptions that represent the exceptions that were thrown by the class loader. The holes in the class array line up with the exceptions.

For example, if the class initializers of one of the classes throws an exception while it is being loaded, a TargetInvocationException is stored in the corresponding element of the LoaderExceptions array.

.NET Framework Security:
ReflectionPermission Reflection permission for the current module.
See also:
ReflectionTypeLoadException

Return to top


Overloaded Method: GetTypeToken(
   string name
)
Summary
Returns the token used to identify the type given its name.
C# Syntax:
public TypeToken GetTypeToken(
   string name
);
Parameters:

name

A string representing the name of the class.

Return Value:
Returns the TypeToken used to identify the type given by name within this module.
Exceptions
Exception Type Condition
ArgumentException type is a ByRef or type is a SymbolType that is not a pointer or an array.
ArgumentNullException type is null.
InvalidOperationException This is a non-transient module that references a transient module.
TypeLoadException The type named name cannot be found.
Remarks
This method is useful for clients of the MethodRental class who want to directly modify the body of a method.

Return to top


Overloaded Method: GetTypeToken(
   Type type
)
Summary
Returns the token used to identify the specified type within this module.
C# Syntax:
public TypeToken GetTypeToken(
   Type type
);
Parameters:

type

The type object that represents the class type.

Return Value:
Returns the TypeToken used to identify the given type within this module.
Exceptions
Exception Type Condition
ArgumentException type is a ByRef or type is a SymbolType that is not a pointer or an array.
ArgumentNullException type is null.
InvalidOperationException A non-transient module that references a transient module.
Remarks
Tokens are used in Microsoft intermediate language (MSIL) instructions to identify objects. Tokens are relative to the module in which they are contained. For example, the token value for String is likely to be different from module to module. When GetTypeToken is invoked, a reference is added to the module. The reference becomes a permanent part of the module; multiple calls with the same argument have no additional affect.

Return to top


Method: IsDefined(
   Type attributeType,
   bool inherit
)
Inherited
See base class member description: System.Reflection.Module.IsDefined

Summary
Determines if the specified attributeType is defined on this module.
C# Syntax:
public virtual bool IsDefined(
   Type attributeType,
   bool inherit
);
Parameters:

attributeType

The Type object to which the custom attribute is applied.

inherit

This argument is ignored for objects of this type.

Return Value:
true if one or more instance of attributeType is defined on this module; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException attributeType is null.
Implements:
ICustomAttributeProvider.IsDefined

Return to top


Method: IsResource()
Inherited
See base class member description: System.Reflection.Module.IsResource

Summary
Gets a value indicating whether the object is a resource.
C# Syntax:
public bool IsResource();
Return Value:
true if the object is a resource; otherwise, false.

Return to top


Method: IsTransient()
Summary
Checks if this dynamic module is transient.
C# Syntax:
public bool IsTransient();
Return Value:
Returns true if this dynamic module is transient; otherwise, false.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: SetCustomAttribute(
   CustomAttributeBuilder customBuilder
)
Summary
Set a custom attribute using a custom attribute builder.
C# Syntax:
public void SetCustomAttribute(
   CustomAttributeBuilder customBuilder
);
Parameters:

customBuilder

An instance of a helper class to define the custom attribute.

Exceptions
Exception Type Condition
ArgumentNullException con is null.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit

Return to top


Overloaded Method: SetCustomAttribute(
   ConstructorInfo con,
   byte[] binaryAttribute
)
Summary
Set a custom attribute using a specified custom attribute blob.
C# Syntax:
public void SetCustomAttribute(
   ConstructorInfo con,
   byte[] binaryAttribute
);
Parameters:

con

The constructor for the custom attribute.

binaryAttribute

A byte blob representing the attributes.

Exceptions
Exception Type Condition
ArgumentNullException con or binaryAttribute is null.
Remarks
See the metadata specifications in the Tool Developers Guide for details on how to format binaryAttribute.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit

Return to top


Method: SetSymCustomAttribute(
   string name,
   byte[] data
)
Summary
Sets the custom attribute that is stored with the symbolic information.
C# Syntax:
public void SetSymCustomAttribute(
   string name,
   byte[] data
);
Parameters:

name

The name of the custom attribute

data

An opaque blob of bytes that represents the value of the custom attribute.

Exceptions
Exception Type Condition
ArgumentNullException url is null.
InvalidOperationException This method is called on a dynamic module that is not a debug module.
Remarks
The custom attribute that is set by this method is associated only with the symbolic information written by the symbol writer and is different from the custom attribute set using the ModuleBuilder.SetCustomAttribute method.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit

Return to top


Method: SetUserEntryPoint(
   MethodInfo entryPoint
)
Summary
Sets the user entry point.
C# Syntax:
public void SetUserEntryPoint(
   MethodInfo entryPoint
);
Parameters:

entryPoint

The user entry point.

Exceptions
Exception Type Condition
ArgumentNullException entryPoint is null.
InvalidOperationException This method is called on a dynamic module that is not a debug module.

-or-

entryPoint is not contained in this dynamic module.

Remarks
The compiler might generate a startup stub before calling user main. The startup stub will be the entry point. While the user main will be the user entry point so that debugger will not step into the compiler entry point.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit

Return to top


Method: ToString()
Inherited
See base class member description: System.Reflection.Module.ToString

Summary
Returns the name of the module.
C# Syntax:
public override string ToString();
Return Value:
A String representing the name of this module.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.