public override FieldInfo BindToField(BindingFlags bindingAttr, FieldInfo[] match, object value, CultureInfo cultureInfo) { int num; if (match == null) { throw new ArgumentNullException("match"); } int num2 = 0; Type c = null; FieldInfo[] infoArray = (FieldInfo[]) match.Clone(); if ((bindingAttr & BindingFlags.SetField) != BindingFlags.Default) { c = value.GetType(); for (num = 0; num < infoArray.Length; num++) { Type fieldType = infoArray[num].FieldType; if (fieldType == c) { infoArray[num2++] = infoArray[num]; } else if ((value == Empty.Value) && fieldType.IsClass) { infoArray[num2++] = infoArray[num]; } else if (fieldType == typeof(object)) { infoArray[num2++] = infoArray[num]; } else if (fieldType.IsPrimitive) { if (CanConvertPrimitiveObjectToType(value, (RuntimeType) fieldType)) { infoArray[num2++] = infoArray[num]; } } else if (fieldType.IsAssignableFrom(c)) { infoArray[num2++] = infoArray[num]; } } switch (num2) { case 0: throw new MissingFieldException(Environment.GetResourceString("MissingField")); case 1: return infoArray[0]; } } int index = 0; bool flag = false; for (num = 1; num < num2; num++) { switch (FindMostSpecificField(infoArray[index], infoArray[num])) { case 0: flag = true; break; case 2: index = num; flag = false; break; } } if (flag) { throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException")); } return infoArray[index]; }
[System.Security.SecuritySafeCritical] // auto-generated public override FieldInfo BindToField(BindingFlags bindingAttr,FieldInfo[] match, Object value,CultureInfo cultureInfo) { if (match == null) { throw new ArgumentNullException("match"); } int i; // Find the method that match... int CurIdx = 0; Type valueType = null; FieldInfo[] candidates = (FieldInfo[]) match.Clone(); // If we are a FieldSet, then use the value's type to disambiguate if ((bindingAttr & BindingFlags.SetField) != 0) { valueType = value.GetType(); for (i=0;i<candidates.Length;i++) { Type pCls = candidates[i].FieldType; if (pCls == valueType) { candidates[CurIdx++] = candidates[i]; continue; } if (value == Empty.Value) { // the object passed in was null which would match any non primitive non value type if (pCls.IsClass) { candidates[CurIdx++] = candidates[i]; continue; } } if (pCls == typeof(Object)) { candidates[CurIdx++] = candidates[i]; continue; } if (pCls.IsPrimitive) { if (CanConvertPrimitiveObjectToType(value,(RuntimeType)pCls)) { candidates[CurIdx++] = candidates[i]; continue; } } else { if (pCls.IsAssignableFrom(valueType)) { candidates[CurIdx++] = candidates[i]; continue; } } } if (CurIdx == 0) throw new MissingFieldException(Environment.GetResourceString("MissingField")); if (CurIdx == 1) return candidates[0]; } // Walk all of the methods looking the most specific method to invoke int currentMin = 0; bool ambig = false; for (i=1;i<CurIdx;i++) { int newMin = FindMostSpecificField(candidates[currentMin], candidates[i]); if (newMin == 0) ambig = true; else { if (newMin == 2) { currentMin = i; ambig = false; } } } if (ambig) throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException")); return candidates[currentMin]; }
public override FieldInfo BindToField(BindingFlags bindingAttr, FieldInfo[] match, object value, CultureInfo cultureInfo) { if (match == null) { throw new ArgumentNullException("match"); } int num = 0; FieldInfo[] array = (FieldInfo[])match.Clone(); if ((bindingAttr & BindingFlags.SetField) != BindingFlags.Default) { Type type = value.GetType(); for (int i = 0; i < array.Length; i++) { Type fieldType = array[i].FieldType; if (fieldType == type) { array[num++] = array[i]; } else { if (value == Empty.Value && fieldType.IsClass) { array[num++] = array[i]; } else { if (fieldType == typeof(object)) { array[num++] = array[i]; } else { if (fieldType.IsPrimitive) { if (DefaultBinder.CanConvertPrimitiveObjectToType(value, (RuntimeType)fieldType)) { array[num++] = array[i]; } } else { if (fieldType.IsAssignableFrom(type)) { array[num++] = array[i]; } } } } } } if (num == 0) { throw new MissingFieldException(Environment.GetResourceString("MissingField")); } if (num == 1) { return array[0]; } } int num2 = 0; bool flag = false; for (int i = 1; i < num; i++) { int num3 = DefaultBinder.FindMostSpecificField(array[num2], array[i]); if (num3 == 0) { flag = true; } else { if (num3 == 2) { num2 = i; flag = false; } } } if (flag) { throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException")); } return array[num2]; }