System.Reflection.BindingFlags Enumeration

Specifies flags that control binding and the way in which the search for members and types is conducted by reflection.

Syntax

[System.Flags]
[System.Runtime.InteropServices.ComVisible(true)]
public enum BindingFlags

Remarks

These BindingFlags control binding for a great many classes in the System, System.Reflection, and System.Runtime namespaces that invoke, create, get, set, and find members and types.

BindingFlags are used in the following Type methods and other places such as MethodBase.Invoke(object, BindingFlags, Binder, Object[], System.Globalization.CultureInfo) :

InvokeMember and GetMethod are especially important.

The binding flags can be categorized by how they identify a type member, as listed in the following table.

BindingFlags.DeclaredOnly

BindingFlags.FlattenHierarchy

BindingFlags.IgnoreCase

BindingFlags.IgnoreReturn

BindingFlags.Instance

BindingFlags.NonPublic

BindingFlags.Public

BindingFlags.Static

BindingFlags.ExactBinding

BindingFlags.OptionalParamBinding

BindingFlags.CreateInstance

BindingFlags.GetField

BindingFlags.SetField

BindingFlags.GetProperty

BindingFlags.SetProperty

BindingFlags.InvokeMethod

BindingFlags.PutDispProperty

BindingFlags.PutRefDispProperty

Note:

You must specify Instance or Static along with Public or NonPublic or no members will be returned.

The following table lists the coercions performed by the default Binder.ChangeType(object, Type, System.Globalization.CultureInfo). This table applies especially to the ExactBinding binding flag.

Any type

Its base type.

Any type

The interface it implements.

Char

UInt16, UInt32, Int32, UInt64, Int64, Single, Double

Byte

Char, UInt16, Int16, UInt32, Int32, UInt64, Int64, Single, Double

SByte

Int16, Int32, Int64, Single, Double

UInt16

UInt32, Int32, UInt64, Int64, Single, Double

Int16

Int32, Int64, Single, Double

UInt32

UInt64, Int64, Single, Double

Int32

Int64, Single, Double

UInt64

Single, Double

Int64

Single, Double

Single

Double

Non-reference

By-reference.

Members

Member NameDescription
CreateInstance

Specifies that Reflection should create an instance of the specified type. Calls the constructor that matches the given arguments. The supplied member name is ignored. If the type of lookup is not specified, (Instance | Public) will apply. It is not possible to call a type initializer.

DeclaredOnly

Specifies that only members declared at the level of the supplied type's hierarchy should be considered. Inherited members are not considered.

Default

Specifies no binding flag.

ExactBinding

Specifies that types of the supplied arguments must exactly match the types of the corresponding formal parameters. Reflection throws an exception if the caller supplies a non-null Binder object, since that implies that the caller is supplying BindToXXX implementations that will pick the appropriate method.

FlattenHierarchy

Specifies that public and protected static members up the hierarchy should be returned. Private static members in inherited classes are not returned. Static members include fields, methods, events, and properties. Nested types are not returned.

GetField

Specifies that the value of the specified field should be returned.

GetProperty

Specifies that the value of the specified property should be returned.

IgnoreCase

Specifies that the case of the member name should not be considered when binding.

IgnoreReturn

Used in COM interop to specify that the return value of the member can be ignored.

Instance

Specifies that instance members are to be included in the search.

InvokeMethod

Specifies that a method is to be invoked. This must not be a constructor or a type initializer.

NonPublic

Specifies that non-public members are to be included in the search.

OptionalParamBinding

Returns the set of members whose parameter count matches the number of supplied arguments. This binding flag is used for methods with parameters that have default values and methods with variable arguments (varargs). This flag should only be used with Type.InvokeMember(string, BindingFlags, Binder, object, Object[], ParameterModifier[], System.Globalization.CultureInfo, String[]).

Public

Specifies that public members are to be included in the search.

PutDispProperty

Specifies that the PROPPUT member on a COM object should be invoked. PROPPUT specifies a property-setting function that uses a value. Use PutDispProperty if a property has both PROPPUT and PROPPUTREF and you need to distinguish which one is called.

PutRefDispProperty

Specifies that the PROPPUTREF member on a COM object should be invoked. PROPPUTREF specifies a property-setting function that uses a reference instead of a value. Use PutRefDispProperty if a property has both PROPPUT and PROPPUTREF and you need to distinguish which one is called.

SetField

Specifies that the value of the specified field should be set.

SetProperty

Specifies that the value of the specified property should be set. For COM properties, specifying this binding flag is equivalent to specifying PutDispProperty and PutRefDispProperty.

Static

Specifies that static members are to be included in the search.

SuppressChangeType

Not implemented.

Requirements

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