19.1.4.A second form of GetMethods() lets you specify various flags that filter the methods that are retrieved. |
|
It has this general form: |
MethodInfo[ ] GetMethods(BindingFlags criteria)
|
|
This version obtains only those methods that match the criteria. |
BindingFlags is an enumeration. |
Its most commonly used values are shown here: |
Value | Meaning | DeclaredOnly | Retrieves only those methods defined by the specified class. Inherited methods are not included. | Instance | Retrieves instance methods. | NonPublic | Retrieves nonpublic methods. | Public | Retrieves public methods. | Static | Retrieves static methods. |
|
- You can OR together two or more flags.
- Minimally you must include either Instance or Static with Public or NonPublic.
- Failure to do so will result in no methods being retrieved.
|
One of the main uses of the BindingFlags form of GetMethods() is to obtain a list of the methods defined by a class without also retrieving the inherited methods. |
For example, try substituting this call to GetMethods() into the preceding program: |
MethodInfo[] mi = t.GetMethods(BindingFlags.DeclaredOnly |
BindingFlags.Instance |
BindingFlags.Public) ;
|
|