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

定义

基于指定的判据,从给定的字段集中选择一个字段。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

参数

bindingAttr
BindingFlags

BindingFlags 值的按位组合。A bitwise combination of BindingFlags values.

match
FieldInfo[]

用于匹配的候选字段集。The set of fields that are candidates for matching. 例如,当 Binder 使用 InvokeMember 对象时,此参数将指定反射已确定为可能匹配项的字段集,通常是因为它们有正确的成员名称。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. DefaultBinder 提供的默认实现会更改此数组的顺序。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

一个 CultureInfo 实例,用于在强制类型的联编程序实现中控制数据类型强制。An instance of CultureInfo that is used to control the coercion of data types, in binder implementations that coerce types. 如果 culturenull,则使用当前线程的 CultureInfoIf culture is null, the CultureInfo for the current thread is used.

返回

FieldInfo

匹配的字段。The matching field.

例外

对于默认的联编程序,bindingAttr 包括 SetField,并且 match 包含多个与 value 良好匹配且匹配程度相同的字段。For the default binder, bindingAttr includes SetField, and match contains multiple fields that are equally good matches for value. 例如,value 包含一个实现 IMyClass 接口的 MyClass 对象,并且 match 包含一个类型为 MyClass 的字段和一个类型为 IMyClass 的字段。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.

对于默认联编程序,bindingAttr 包括 SetField,并且 match 不包含任何可接受 value 的字段。For the default binder, bindingAttr includes SetField, and match contains no fields that can accept value.

对于默认联编程序,bindingAttr 包括 SetField,并且 matchnull 或一个空数组。For the default binder, bindingAttr includes SetField, and match is null or an empty array.

- 或 --or- bindingAttr 包括 SetField,并且 valuenullbindingAttr includes SetField, and value is null.

注解

如果不 bindingAttr 包括 BindingFlags.SetField ,则提供的默认联编程序实现 Type.DefaultBinder 只返回的第一个元素 matchIf 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.

此方法控制由提供的绑定 Type.InvokeMemberThis method controls the binding provided by Type.InvokeMember.

如果联编程序实现允许将字符串值强制转换为数值类型,则 culture 参数对于将表示1000的字符串转换为值是必需的 Double ,因为不同的区域性以不同的方式表示1000。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.

适用于

另请参阅