C# TypeInfo GetMember(String, MemberTypes, BindingFlags)

Description

TypeInfo GetMember(String, MemberTypes, BindingFlags) Searches for the specified members of the specified member type, using the specified binding constraints.

Syntax

TypeInfo.GetMember(String, MemberTypes, BindingFlags) has the following syntax.


public virtual MemberInfo[] GetMember(
  string name,/*from w  w w  .  j  a va 2  s .c  o m*/
  MemberTypes type,
  BindingFlags bindingAttr
)

Parameters

TypeInfo.GetMember(String, MemberTypes, BindingFlags) has the following parameters.

  • name - The string containing the name of the members to get.
  • type - The value to search for.
  • bindingAttr - A bitmask comprised of one or more BindingFlags that specify how the search is conducted.
  • bindingAttr - -or-
  • bindingAttr - Zero, to return an empty array.

Returns

TypeInfo.GetMember(String, MemberTypes, BindingFlags) method returns

Example


using System;//from  w w w  .j  av  a2  s .  c o m
using System.Security;
using System.Reflection;

public class MyMemberSample 
{
    public static void Main()
    {
        String myString = "GetMember_String_MemberType_BindingFlag";
        Type myType = myString.GetType();
        // Get the public instance methods for myString starting with the letter C.
        MemberInfo[] myMembers = myType.GetMember("C*", MemberTypes.Method, 
            BindingFlags.Public | BindingFlags.Instance);
        if(myMembers.Length > 0)
        {
            Console.WriteLine("\nThe public instance method(s) starting with the letter C for type {0}:", myType);
            for(int index=0; index < myMembers.Length; index++)
                Console.WriteLine("Member {0}: {1}", index + 1, myMembers[index].ToString());
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Reflection »




EventInfo
FieldInfo
MemberInfo
MethodInfo
ParameterInfo
TypeInfo