C# Type GetMember(String, MemberTypes, BindingFlags)
Description
Type GetMember(String, MemberTypes, BindingFlags)
searches
for the specified members of the specified member type, using the specified
binding constraints.
Syntax
Type.GetMember(String, MemberTypes, BindingFlags)
has the following syntax.
public virtual MemberInfo[] GetMember(
string name,// w ww.j av a 2 s . co m
MemberTypes type,
BindingFlags bindingAttr
)
Parameters
Type.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
Type.GetMember(String, MemberTypes, BindingFlags)
method returns
Example
The following example displays all the methods of the myString class that start with the letter C.
/*from w w w. j a va2s . c o m*/
using System;
using System.Reflection;
public class MainClass{
public static void Main(String[] argv){
String myString = "java2s.com";
Type myType = myString.GetType();
MemberInfo[] myMembers = myType.GetMember("C*", MemberTypes.Method, BindingFlags.Public | BindingFlags.Instance);
if(myMembers.Length > 0)
{
Console.WriteLine(myType);
for(int index=0; index < myMembers.Length; index++){
Console.WriteLine("Member {0}: {1}", index + 1, myMembers[index].ToString());
}
}
else
Console.WriteLine("No members match the search criteria.");
}
}
The code above generates the following result.