System.Reflection.Module Class

Assembly: Mscorlib.dll
Namespace: System.Reflection
Summary
Performs reflection on a module.
C# Syntax:
[Serializable]
public class Module : ISerializable, ICustomAttributeProvider
Remarks
A module is a portable executable file of type .dll or .exe consisting of one or more classes and interfaces. There may be multiple namespaces contained in a single module, and a namespace may span multiple modules.

One or more modules deployed as a unit compose an assembly.

See also:
System.Reflection Namespace

System.Reflection.Module Member List:

Public Fields
FilterTypeName A TypeFilter object that filters the list of types defined in this module based upon the name. This field is case-sensitive and read-only.
FilterTypeNameIgnoreCase A TypeFilter object that filters the list of types defined in this module based upon the name. This field is case-insensitive and read-only.
Public Properties
Assembly Read-only

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

Gets a string representing the fully qualified name and path to this module.
Name Read-only

Gets a String representing the name of the module with the path removed.
ScopeName Read-only

Gets a string representing the name of the module.
Public Methods
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 Returns an array of classes accepted by the given filter and filter criteria.
GetCustomAttributes Overloaded:
GetCustomAttributes(bool inherit)

Returns all custom attributes.
GetCustomAttributes Overloaded:
GetCustomAttributes(Type attributeType, bool inherit)

Gets custom attributes of the specified type.
GetField Overloaded:
GetField(string name)

Returns a field having the specified name.
GetField Overloaded:
GetField(string name, BindingFlags bindingAttr)

Returns a field having the specified name and binding attributes.
GetFields Returns an array of fields implemented by a class.
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 Overloaded:
GetMethod(string name)

Returns a method having the specified name.
GetMethod Overloaded:
GetMethod(string name, Type[] types)

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

Returns a method having the specified name, binding information, calling convention, and parameter types and modifiers.
GetMethods Returns an array of all the global methods defined on the module.
GetObjectData Provides an ISerializable implementation for serialized objects.
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)

Returns the specified class, performing a case-sensitive search.
GetType Overloaded:
GetType(string className, bool ignoreCase)

Returns the specified class, searching the module with the specified case sensitivity.
GetType Overloaded:
GetType(string className, bool throwOnError, bool ignoreCase)

Returns the specified class, searching the module with the specified case sensitivity and specifying whether to throw an exception if an error occurs while loading the Type.
GetTypes Returns all the classes defined within this module.
IsDefined Determines if the specified attributeType is defined on this module.
IsResource Gets a value indicating whether the object is a resource.
ToString Overridden:
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 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.Module Member Details

Field: FilterTypeName
Summary
A TypeFilter object that filters the list of types defined in this module based upon the name. This field is case-sensitive and read-only.
C# Syntax:
public static readonly TypeFilter FilterTypeName;
Remarks
The filter supports a trailing "*" wildcard.
See also:
Module.FindTypes

Return to top


Field: FilterTypeNameIgnoreCase
Summary
A TypeFilter object that filters the list of types defined in this module based upon the name. This field is case-insensitive and read-only.
C# Syntax:
public static readonly TypeFilter FilterTypeNameIgnoreCase;
Remarks
The filter supports a trailing "*" wildcard.
See also:
Module.FindTypes

Return to top


Property: Assembly (read-only)
Summary
Gets the appropriate Assembly for this instance of Module.
C# Syntax:
public Assembly Assembly {get;}

Return to top


Property: FullyQualifiedName (read-only)
Summary
Gets a string representing the fully qualified name and path to this module.
C# Syntax:
public virtual string FullyQualifiedName {get;}
Exceptions
Exception Type Condition
SecurityException The caller does not have the required permissions.
Remarks
To get the name without the path, use Module.Name.

If the assembly for this module was loaded from a byte array then the FullyQualifiedName for the module will be: <Unknown>.



Note The case of module name is platform-dependent.
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
 */

    
.NET Framework Security:
FileIOPermission for access to information in the path. Associated enumeration: FileIOPermissionAccess.PathDiscovery.

Return to top


Property: Name (read-only)
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)
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: 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:
~Module();

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

Return to top


Method: FindTypes(
   TypeFilter filter,
   object filterCriteria
)
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


Overloaded Method: GetCustomAttributes(
   bool inherit
)
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
)
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
)
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
)
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()
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: 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
)
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
)
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
)
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
)
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()
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: GetObjectData(
   SerializationInfo info,
   StreamingContext context
)
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: 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
Returns the specified class, performing a case-sensitive search.
C# Syntax:
public virtual Type GetType(
   string className
);
Parameters:

className

The name of the class to locate. The name must be fully qualified with the namespace.

Return Value:
A Type object representing the given class name, if the class is in this module; otherwise, null.
Exceptions
Exception Type Condition
ArgumentNullException className is null.
TargetInvocationException The class initializers are invoked and an exception is thrown.
ArgumentException className is invalid, such as if it is greater than 1023 characters or if it is a zero-length string.
SecurityException The caller does not have the required reflection permissions and attempts to reflect on a type that is not public.
.NET Framework Security:
ReflectionPermission for reflecting on types that are not public. Associated enumeration: ReflectionPermissionFlag.TypeInformation

Return to top


Overloaded Method: GetType(
   string className,
   bool ignoreCase
)
Summary
Returns the specified class, searching the module with the specified case sensitivity.
C# Syntax:
public virtual Type GetType(
   string className,
   bool ignoreCase
);
Parameters:

className

The name of the class to locate. The name must be fully qualified with the namespace.

ignoreCase

true for case-insensitive search; otherwise, false.

Return Value:
A Type object representing the given class name, if the class is in this module; otherwise, null.
Exceptions
Exception Type Condition
ArgumentNullException className is null.
TargetInvocationException The class initializers are invoked and an exception is thrown.
ArgumentException className is invalid, such as if it is greater than 1023 characters or if it is a zero-length string.
SecurityException The caller does not have the required reflection permissions and attempts to reflect on a type that is not public.
.NET Framework Security:
ReflectionPermission for reflecting on types that are not public. Associated enumeration: ReflectionPermissionFlag.TypeInformation

Return to top


Overloaded Method: GetType(
   string className,
   bool throwOnError,
   bool ignoreCase
)
Summary
Returns the specified class, searching the module with the specified case sensitivity and specifying whether to throw an exception if an error occurs while loading the Type.
C# Syntax:
public virtual Type GetType(
   string className,
   bool throwOnError,
   bool ignoreCase
);
Parameters:

className

The name of the class to locate. The name must be fully qualified with the namespace.

throwOnError

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

-or-

false to ignore errors while loading the Type.

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

-or-

false to ignore errors while loading the Type.

ignoreCase

true for case-insensitive search; otherwise, false.

Return Value:
A Type object representing the given class name, if the class is in this module; otherwise, null.
Exceptions
Exception Type Condition
ArgumentNullException className is null.
TargetInvocationException The class initializers are invoked and an exception is thrown.
ArgumentException className is invalid, such as if it is greater than 1023 characters or if it is a zero-length string.
TypeLoadException An error occurred while loading the type.
SecurityException The caller does not have the required reflection permissions and attempts to reflect on a type that is not public.
.NET Framework Security:
ReflectionPermission for reflecting on types that are not public. Associated enumeration: ReflectionPermissionFlag.TypeInformation

Return to top


Method: GetTypes()
Summary
Returns all the classes defined within this module.
C# Syntax:
public virtual 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 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.

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


Method: IsDefined(
   Type attributeType,
   bool inherit
)
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()
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: 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


Overridden Method: 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.