PostSharp 2023.0 / / Post­Sharp Documentation / API Reference / Post­Sharp.​Reflection Namespace / Custom­Reflection­Binder Class / Custom­Reflection­Binder Methods / Custom­Reflection­Binder.​Bind­To­Field Method

CustomReflectionBinder.BindToField Method

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

Namespace:  PostSharp.Reflection
Assembly:  PostSharp (in PostSharp.dll) Version: 2023.0.3.0 (2023.0.3.0)
public override FieldInfo BindToField(
	BindingFlags bindingFlags,
	FieldInfo[] match,
	Object value,
	CultureInfo culture


Type: System.Reflection.BindingFlags
Type: System.Reflection.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.
Type: System.Object
The field value used to locate a matching field.
Type: System.Globalization.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.Note   For example, if a binder implementation allows coercion of string values to numeric types, this 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.

Return Value

Type: FieldInfo
The matching field.
AmbiguousMatchExceptionFor 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.
MissingFieldExceptionFor the default binder, bindingAttr includes SetField, and match contains no fields that can accept value.
NullReferenceExceptionFor the default binder, bindingAttr includes SetField, and match is null or an empty array.-or- bindingAttr includes SetField, and value is null.
See Also