Export (0) Print
Expand All
Expand Minimize

BindingFlags Enumeration

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

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

Namespace:  System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

[<SerializableAttribute>]
[<FlagsAttribute>]
[<ComVisibleAttribute(true)>]
type BindingFlags

Member nameDescription
Supported by the XNA FrameworkCreateInstanceSpecifies 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.
Supported by the XNA FrameworkSupported by Portable Class LibraryDeclaredOnlySpecifies that only members declared at the level of the supplied type's hierarchy should be considered. Inherited members are not considered.
Supported by the XNA FrameworkDefaultSpecifies no binding flag.
Supported by the XNA FrameworkSupported by Portable Class LibraryExactBindingSpecifies 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.

Reflection models the accessibility rules of the common type system. For example, if the caller is in the same assembly, the caller does not need special permissions for internal members. Otherwise, the caller needs ReflectionPermission. This is consistent with lookup of members that are protected, private, and so on.

The general principle is that ChangeType should perform only widening coercions, which never lose data. An example of a widening coercion is coercing a value that is a 32-bit signed integer to a value that is a 64-bit signed integer. This is distinguished from a narrowing coercion, which may lose data. An example of a narrowing coercion is coercing a 64-bit signed integer to a 32-bit signed integer.

The default binder ignores this flag, while custom binders can implement the semantics of this flag.

Supported by the XNA FrameworkSupported by Portable Class LibraryFlattenHierarchySpecifies 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.
Supported by the XNA FrameworkGetFieldSpecifies that the value of the specified field should be returned.
Supported by the XNA FrameworkGetPropertySpecifies that the value of the specified property should be returned.
Supported by the XNA FrameworkSupported by Portable Class LibraryIgnoreCaseSpecifies that the case of the member name should not be considered when binding.
Supported by the XNA FrameworkIgnoreReturnUsed in COM interop to specify that the return value of the member can be ignored.
Supported by the XNA FrameworkSupported by Portable Class LibraryInstanceSpecifies that instance members are to be included in the search.
Supported by the XNA FrameworkInvokeMethodSpecifies that a method is to be invoked. This must not be a constructor or a type initializer.
Supported by the XNA FrameworkSupported by Portable Class LibraryNonPublicSpecifies that non-public members are to be included in the search.
Supported by the XNA FrameworkSupported by Portable Class LibraryOptionalParamBindingReturns 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.

Parameters with default values are used only in calls where trailing arguments are omitted. They must be the last arguments.

Supported by the XNA FrameworkSupported by Portable Class LibraryPublicSpecifies that public members are to be included in the search.
Supported by the XNA FrameworkPutDispPropertySpecifies 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.
Supported by the XNA FrameworkPutRefDispPropertySpecifies 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.
Supported by the XNA FrameworkSetFieldSpecifies that the value of the specified field should be set.
Supported by the XNA FrameworkSetPropertySpecifies that the value of the specified property should be set. For COM properties, specifying this binding flag is equivalent to specifying PutDispProperty and PutRefDispProperty.
Supported by the XNA FrameworkSupported by Portable Class LibraryStaticSpecifies that static members are to be included in the search.
Supported by the XNA FrameworkSuppressChangeTypeNot implemented.

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 :

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.

Identified by Accessibility

Identified by Binding Argument

Identified by Operation

DeclaredOnly

FlattenHierarchy

IgnoreCase

IgnoreReturn

Instance

NonPublic

Public

Static

ExactBinding

OptionalParamBinding

CreateInstance

GetField

SetField

GetProperty

SetProperty

InvokeMethod

PutDispProperty

PutRefDispProperty

NoteNote

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. This table applies especially to the ExactBinding binding flag.

Source Type

Target Type

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.

The following example demonstrates many of the binding flags.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft