Export (0) Print
Expand All

MemberInfo.Module Property

Note: This property is new in the .NET Framework version 2.0.

Gets the module in which the type that declares the member represented by the current MemberInfo is defined.

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

public virtual Module Module { get; }
/** @property */
public Module get_Module ()

public function get Module () : Module

Property Value

The Module in which the type that declares the member represented by the current MemberInfo is defined.

This property is provided as a convenience. It is equivalent to using the DeclaringType property to get the type in which the method is declared, and then calling the Module property of the resulting Type object.

The following code example declares a class that inherits Object and overrides Object.ToString. The example obtains MethodInfo objects for the class's ToString method and for the inherited GetHashCode method, and displays the names of the modules in which the two methods are declared.

using System;
using System.Reflection;

public class Test
{
    public override string ToString()
    {
        return "An instance of class Test!";
    }
}

public class Example
{
    public static void Main()
    {
        Test t = new Test();
        MethodInfo mi = t.GetType().GetMethod("ToString");
        Console.WriteLine("{0} is defined in {1}", mi.Name, mi.Module.Name);

        mi = t.GetType().GetMethod("GetHashCode");
        Console.WriteLine("{0} is defined in {1}", mi.Name, mi.Module.Name);
    }
}

/* This example produces code similar to the following:

  ToString is defined in source.exe
  GetHashCode is defined in mscorlib.dll
 */

import System.*;
import System.Reflection.*;

public class Test
{
    public String ToString()
    {
        return "An instance of class Test!";
    } //ToString
} //Test

public class Example
{
    public static void main(String[] args)
    {
        Test t = new Test();
        MethodInfo mi = t.GetType().GetMethod("ToString");
        Console.WriteLine("{0} is defined in {1}", mi.get_Name(), 
            mi.get_Module().get_Name());

        mi = t.GetType().GetMethod("GetHashCode");
        Console.WriteLine("{0} is defined in {1}", mi.get_Name(), 
            mi.get_Module().get_Name());
    } //main
} //Example

/* This example produces code similar to the following:

  ToString is defined in source.exe
  GetHashCode is defined in mscorlib.dll
 */

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2015 Microsoft