System.Reflection.MemberInfo Class

public abstract class MemberInfo

Base Types

Object
  MemberInfo

Assembly

mscorlib

Library

Reflection

Summary

Provides access to member metadata.

Description

[Note: MemberInfo is used to represent all members of a type: nested types, fields, events, properties, methods, and constructors. The Base Class Library includes the following derived types:

]

See Also

System.Reflection Namespace

Members

MemberInfo Constructors

MemberInfo Constructor

MemberInfo Properties

MemberInfo.DeclaringType Property
MemberInfo.Name Property
MemberInfo.ReflectedType Property


MemberInfo Constructor

protected MemberInfo();

Summary

Constructs a new instance of the MemberInfo class.

See Also

System.Reflection.MemberInfo Class, System.Reflection Namespace

MemberInfo.DeclaringType Property

public abstract Type DeclaringType { get; }

Summary

Gets the type that declares the member reflected by the current instance.

Property Value

The Type object of the class that declares the member reflected by the current instance; or, null if the member reflected by the current instance is a global member.

Description

[Note: A member of a class (or interface) is either declared on that type or inherited from a base class (or interface). The System.Reflection.MemberInfo.DeclaringType property value cannot be the same as the Type object used to obtain the current instance. These values will differ if either of the following conditions is true.

]

[Behaviors: This property is read-only.

This property is required to return the Type object for the type that declares the member reflected by the current instance. This property value is required to be equal to the System.Reflection.MemberInfo.ReflectedType property value of the current instance if and only if the reflected type also contains a declaration for the member reflected by the current instance.

]

[Overrides: Override this property to get the Type of the class that declared the member that is reflected by the current instance.]

[Usage: Use this property to determine the Type of the class that declared the member that is reflected by the current instance.]

Example

The following example demonstrates the difference between the System.Reflection.MemberInfo.DeclaringType and System.Reflection.MemberInfo.ReflectedType of a member.

using System;
using System.Reflection;

public class BaseClass {
   public void ReflectedMethod() {}
}

public class DerivedClass: BaseClass {}

public class DeclaringTypeExample {
   public static void Main() {
    Type t = typeof(DerivedClass);
    MemberInfo [] memInfo = t.GetMember("ReflectedMethod");
    Console.WriteLine("Reflected type is {0}.", memInfo[0].ReflectedType);
    Console.WriteLine("Declaring type is {0}.", memInfo[0].DeclaringType);    
   }
}
   
The output is

Reflected type is DerivedClass.

Declaring type is BaseClass.

See Also

System.Reflection.MemberInfo Class, System.Reflection Namespace

MemberInfo.Name Property

public abstract string Name { get; }

Summary

Gets the name of the member reflected by the current instance.

Property Value

A String containing the name of the member reflected by the current instance.

Description

[Behaviors: This property is read-only.

Only the simple name, not the fully qualified name, of the member reflected by the current instance is returned.

[Note: For example, if the current instance reflects the member Print in System.MyClass, the System.Reflection.MemberInfo.Name property would be "Print".]

]

See Also

System.Reflection.MemberInfo Class, System.Reflection Namespace

MemberInfo.ReflectedType Property

public abstract Type ReflectedType { get; }

Summary

Gets the type of the class through which the current instance was obtained.

Property Value

The Type object for the class through which the current instance was obtained.

Description

[Behaviors: This property is read-only.

ReflectedType is required to get the type of the object that was used to obtain the current instance. This property value is required to be equal to the System.Reflection.MemberInfo.DeclaringType property value of the current instance if and only if the reflected type also contains a declaration for the member reflected by the current instance.

]

See Also

System.Reflection.MemberInfo Class, System.Reflection Namespace