System.Type.GetMember Method

Searches for the public members with the specified name.

Syntax

public System.Reflection.MemberInfo[] GetMember (string name)

Parameters

name
The string containing the name of the public members to get.

Returns

An array of System.Reflection.MemberInfo objects representing the public members with the specified name, if found; otherwise, an empty array.

Exceptions

TypeReason
ArgumentNullException name is null.

Remarks

The search for name is case-sensitive. The search includes public static and public instance members.

Members include properties, methods, fields, events, and so on.

The Type.GetMember(string) method does not return members in a particular order, such as alphabetical or declaration order. Your code must not depend on the order in which members are returned, because that order varies.

This method overload will not find class initializers (.cctor). To find class initializers, use an overload that takes System.Reflection.BindingFlags, and specify System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic (System.Reflection.BindingFlags.Static Or System.Reflection.BindingFlags.NonPublic in Visual Basic). You can also get the class initializer using the Type.TypeInitializer property.

The following table shows what members of a base class are returned by the Get methods when reflecting on a type.

Constructor

No

No

Field

No

Yes. A field is always hide-by-name-and-signature.

Event

Not applicable

The common type system rule is that the inheritance is the same as that of the methods that implement the property. Reflection treats properties as hide-by-name-and-signature. See note 2 below.

Method

No

Yes. A method (both virtual and non-virtual) can be hide-by-name or hide-by-name-and-signature.

Nested Type

No

No

Property

Not applicable

The common type system rule is that the inheritance is the same as that of the methods that implement the property. Reflection treats properties as hide-by-name-and-signature. See note 2 below.

[The 'ordered' type of list has not been implemented in the ECMA stylesheet.]

If the current Type represents a constructed generic type, this method returns the System.Reflection.MemberInfo with the type parameters replaced by the appropriate type arguments.

If the current Type represents a type parameter in the definition of a generic type or generic method, this method searches the members of the class constraint, or the members of object if there is no class constraint.

Note:

For generic methods, do not include the type arguments in name. For example, the C# code GetMember("MyMethod<int>") searches for a member with the text name "MyMethod<int>", rather than for a method named MyMethod that has one generic argument of type int.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0