A second form of GetMethods() lets you specify various flags that filter the methods that are retrieved. : Type « Reflection « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » Reflection » Type 
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:

ValueMeaning
DeclaredOnlyRetrieves only those methods defined by the specified class. Inherited methods are not included.
InstanceRetrieves instance methods.
NonPublicRetrieves nonpublic methods.
PublicRetrieves public methods.
StaticRetrieves static methods.


  1. You can OR together two or more flags.
  2. Minimally you must include either Instance or Static with Public or NonPublic.
  3. 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;
19.1.Type
19.1.1.Reflection
19.1.2.type identity
19.1.3.Commonly used methods defined by Type:
19.1.4.A second form of GetMethods() lets you specify various flags that filter the methods that are retrieved.
19.1.5.Obtain type information using the Type.GetType method(Case sensitive, return null if not found).
19.1.6.Obtain type information using the Type.GetType method(Case sensitive, throw TypeLoadException if not found)
19.1.7.Obtain type information using the Type.GetType method(Case insensitive, throw TypeLoadException if not found)
19.1.8.Obtain type information using the Object.GetType method
19.1.9.Is object a type
19.1.10.Get BaseType, Name, FullName and Namespace for a type
19.1.11.Type: FullName, BaseType, IsAbstract, IsCOMObject, IsSealed, IsClass
19.1.12.Get the Type representation: object
19.1.13.Obtain the handles: object
19.1.14.Get all methods from a Type
19.1.15.Open and constructed generic types
19.1.16.Getting generic type definition information
19.1.17.Dynamically constructing types
19.1.18.Create StringBuilder
19.1.19.Get Type with typeof
19.1.20.Cast And OfType
19.1.21.Get/set property using invoke member
19.1.22.Retrieve a type by passing a ProgID, specifying whether to throw an exception if the ProgID is invalid.
19.1.23.Get an array of nested type objects in MyClass
19.1.24.Get the type associated with the CLSID and specify whether to throw an exception if an error occurs while loading the type.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.