Binder.BindToField(BindingFlags, FieldInfo[], Object, CultureInfo) Method

Definition

Selects a field from the given set of fields, based on the specified criteria.

public:
 abstract System::Reflection::FieldInfo ^ BindToField(System::Reflection::BindingFlags bindingAttr, cli::array <System::Reflection::FieldInfo ^> ^ match, System::Object ^ value, System::Globalization::CultureInfo ^ culture);
public abstract System.Reflection.FieldInfo BindToField (System.Reflection.BindingFlags bindingAttr, System.Reflection.FieldInfo[] match, object value, System.Globalization.CultureInfo? culture);
public abstract System.Reflection.FieldInfo BindToField (System.Reflection.BindingFlags bindingAttr, System.Reflection.FieldInfo[] match, object value, System.Globalization.CultureInfo culture);
abstract member BindToField : System.Reflection.BindingFlags * System.Reflection.FieldInfo[] * obj * System.Globalization.CultureInfo -> System.Reflection.FieldInfo
Public MustOverride Function BindToField (bindingAttr As BindingFlags, match As FieldInfo(), value As Object, culture As CultureInfo) As FieldInfo

Parameters

bindingAttr
BindingFlags

A bitwise combination of BindingFlags values.

match
FieldInfo[]

The set of fields that are candidates for matching. For example, when a Binder object is used by InvokeMember, this parameter specifies the set of fields that reflection has determined to be possible matches, typically because they have the correct member name. The default implementation provided by DefaultBinder changes the order of this array.

value
Object

The field value used to locate a matching field.

culture
CultureInfo

An instance of CultureInfo that is used to control the coercion of data types, in binder implementations that coerce types. If culture is null, the CultureInfo for the current thread is used.

Returns

The matching field.

Exceptions

For the default binder, bindingAttr includes SetField, and match contains multiple fields that are equally good matches for value. For example, value contains a MyClass object that implements the IMyClass interface, and match contains a field of type MyClass and a field of type IMyClass.

For the default binder, bindingAttr includes SetField, and match contains no fields that can accept value.

For the default binder, bindingAttr includes SetField, and match is null or an empty array.

-or-

bindingAttr includes SetField, and value is null.

Remarks

If bindingAttr does not include BindingFlags.SetField, the default binder implementation provided by Type.DefaultBinder simply returns the first element of match. No selection is done.

This method controls the binding provided by Type.InvokeMember.

If a binder implementation allows coercion of string values to numeric types, the culture parameter is necessary to convert a string that represents 1000 to a Double value, because 1000 is represented differently by different cultures. The default binder does not do such string coercions.

Applies to

See also