private static FindMostSpecificMethod ( |
||
m1 | ||
paramOrder1 | int | |
paramArrayType1 | ||
m2 | ||
paramOrder2 | int | |
paramArrayType2 | ||
types | ||
args | Object | |
return | int |
public override MethodBase SelectMethod(BindingFlags bindingAttr, MethodBase[] match, Type[] types, ParameterModifier[] modifiers) { Type[] array = new Type[types.Length]; for (int i = 0; i < types.Length; i++) { array[i] = types[i].UnderlyingSystemType; if (!(array[i] is RuntimeType)) { throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "types"); } } types = array; if (match == null || match.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), "match"); } MethodBase[] array2 = (MethodBase[])match.Clone(); int num = 0; for (int i = 0; i < array2.Length; i++) { ParameterInfo[] parametersNoCopy = array2[i].GetParametersNoCopy(); if (parametersNoCopy.Length == types.Length) { int j; for (j = 0; j < types.Length; j++) { Type parameterType = parametersNoCopy[j].ParameterType; if (!(parameterType == types[j]) && !(parameterType == typeof(object))) { if (parameterType.IsPrimitive) { if (!(types[j].UnderlyingSystemType is RuntimeType)) { break; } if (!DefaultBinder.CanConvertPrimitive((RuntimeType)types[j].UnderlyingSystemType, (RuntimeType)parameterType.UnderlyingSystemType)) { break; } } else if (!parameterType.IsAssignableFrom(types[j])) { break; } } } if (j == types.Length) { array2[num++] = array2[i]; } } } if (num == 0) { return(null); } if (num == 1) { return(array2[0]); } int num2 = 0; bool flag = false; int[] array3 = new int[types.Length]; for (int i = 0; i < types.Length; i++) { array3[i] = i; } for (int i = 1; i < num; i++) { int num3 = DefaultBinder.FindMostSpecificMethod(array2[num2], array3, null, array2[i], array3, null, types, null); if (num3 == 0) { flag = true; } else if (num3 == 2) { flag = false; num2 = i; } } if (flag) { throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException")); } return(array2[num2]); }
public override MethodBase SelectMethod(BindingFlags bindingAttr, MethodBase[] match, Type[] types, ParameterModifier[] modifiers) { Type[] typeArray = new Type[types.Length]; for (int index = 0; index < types.Length; ++index) { typeArray[index] = types[index].UnderlyingSystemType; if (!(typeArray[index] is RuntimeType)) { throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "types"); } } types = typeArray; if (match == null || match.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), "match"); } MethodBase[] methodBaseArray = (MethodBase[])match.Clone(); int num = 0; for (int index1 = 0; index1 < methodBaseArray.Length; ++index1) { ParameterInfo[] parametersNoCopy = methodBaseArray[index1].GetParametersNoCopy(); if (parametersNoCopy.Length == types.Length) { int index2; for (index2 = 0; index2 < types.Length; ++index2) { Type parameterType = parametersNoCopy[index2].ParameterType; if (!(parameterType == types[index2]) && !(parameterType == typeof(object))) { if (parameterType.IsPrimitive) { if (!(types[index2].UnderlyingSystemType is RuntimeType) || !DefaultBinder.CanConvertPrimitive((RuntimeType)types[index2].UnderlyingSystemType, (RuntimeType)parameterType.UnderlyingSystemType)) { break; } } else if (!parameterType.IsAssignableFrom(types[index2])) { break; } } } if (index2 == types.Length) { methodBaseArray[num++] = methodBaseArray[index1]; } } } if (num == 0) { return((MethodBase)null); } if (num == 1) { return(methodBaseArray[0]); } int index3 = 0; bool flag = false; int[] numArray = new int[types.Length]; for (int index1 = 0; index1 < types.Length; ++index1) { numArray[index1] = index1; } for (int index1 = 1; index1 < num; ++index1) { switch (DefaultBinder.FindMostSpecificMethod(methodBaseArray[index3], numArray, (Type)null, methodBaseArray[index1], numArray, (Type)null, types, (object[])null)) { case 0: flag = true; break; case 2: flag = false; index3 = index1; break; } } if (flag) { throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException")); } return(methodBaseArray[index3]); }
public override MethodBase BindToMethod(BindingFlags bindingAttr, MethodBase[] match, ref object[] args, ParameterModifier[] modifiers, CultureInfo cultureInfo, string[] names, out object state) { if (match == null || match.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), "match"); } MethodBase[] array = (MethodBase[])match.Clone(); state = null; int[][] array2 = new int[array.Length][]; for (int i = 0; i < array.Length; i++) { ParameterInfo[] parametersNoCopy = array[i].GetParametersNoCopy(); array2[i] = new int[(parametersNoCopy.Length > args.Length) ? parametersNoCopy.Length : args.Length]; if (names == null) { for (int j = 0; j < args.Length; j++) { array2[i][j] = j; } } else if (!DefaultBinder.CreateParamOrder(array2[i], parametersNoCopy, names)) { array[i] = null; } } Type[] array3 = new Type[array.Length]; Type[] array4 = new Type[args.Length]; for (int i = 0; i < args.Length; i++) { if (args[i] != null) { array4[i] = args[i].GetType(); } } int num = 0; bool flag = (bindingAttr & BindingFlags.OptionalParamBinding) > BindingFlags.Default; for (int i = 0; i < array.Length; i++) { Type type = null; if (!(array[i] == null)) { ParameterInfo[] parametersNoCopy2 = array[i].GetParametersNoCopy(); if (parametersNoCopy2.Length == 0) { if (args.Length == 0 || (array[i].CallingConvention & CallingConventions.VarArgs) != (CallingConventions)0) { array2[num] = array2[i]; array[num++] = array[i]; } } else { int j; if (parametersNoCopy2.Length > args.Length) { j = args.Length; while (j < parametersNoCopy2.Length - 1 && parametersNoCopy2[j].DefaultValue != DBNull.Value) { j++; } if (j != parametersNoCopy2.Length - 1) { goto IL_426; } if (parametersNoCopy2[j].DefaultValue == DBNull.Value) { if (!parametersNoCopy2[j].ParameterType.IsArray || !parametersNoCopy2[j].IsDefined(typeof(ParamArrayAttribute), true)) { goto IL_426; } type = parametersNoCopy2[j].ParameterType.GetElementType(); } } else if (parametersNoCopy2.Length < args.Length) { int num2 = parametersNoCopy2.Length - 1; if (!parametersNoCopy2[num2].ParameterType.IsArray || !parametersNoCopy2[num2].IsDefined(typeof(ParamArrayAttribute), true) || array2[i][num2] != num2) { goto IL_426; } type = parametersNoCopy2[num2].ParameterType.GetElementType(); } else { int num3 = parametersNoCopy2.Length - 1; if (parametersNoCopy2[num3].ParameterType.IsArray && parametersNoCopy2[num3].IsDefined(typeof(ParamArrayAttribute), true) && array2[i][num3] == num3 && !parametersNoCopy2[num3].ParameterType.IsAssignableFrom(array4[num3])) { type = parametersNoCopy2[num3].ParameterType.GetElementType(); } } int num4 = (type != null) ? (parametersNoCopy2.Length - 1) : args.Length; for (j = 0; j < num4; j++) { Type type2 = parametersNoCopy2[j].ParameterType; if (type2.IsByRef) { type2 = type2.GetElementType(); } if (!(type2 == array4[array2[i][j]]) && (!flag || args[array2[i][j]] != Type.Missing) && args[array2[i][j]] != null && !(type2 == typeof(object))) { if (type2.IsPrimitive) { if (array4[array2[i][j]] == null) { break; } if (!DefaultBinder.CanConvertPrimitiveObjectToType(args[array2[i][j]], (RuntimeType)type2)) { break; } } else if (!(array4[array2[i][j]] == null) && !type2.IsAssignableFrom(array4[array2[i][j]]) && (!array4[array2[i][j]].IsCOMObject || !type2.IsInstanceOfType(args[array2[i][j]]))) { break; } } } if (type != null && j == parametersNoCopy2.Length - 1) { while (j < args.Length) { if (type.IsPrimitive) { if (array4[j] == null) { break; } if (!DefaultBinder.CanConvertPrimitiveObjectToType(args[j], (RuntimeType)type)) { break; } } else if (!(array4[j] == null) && !type.IsAssignableFrom(array4[j]) && (!array4[j].IsCOMObject || !type.IsInstanceOfType(args[j]))) { break; } j++; } } if (j == args.Length) { array2[num] = array2[i]; array3[num] = type; array[num++] = array[i]; } } } IL_426 :; } if (num == 0) { throw new MissingMethodException(Environment.GetResourceString("MissingMember")); } if (num == 1) { if (names != null) { state = new DefaultBinder.BinderState((int[])array2[0].Clone(), args.Length, array3[0] != null); DefaultBinder.ReorderParams(array2[0], args); } ParameterInfo[] parametersNoCopy3 = array[0].GetParametersNoCopy(); if (parametersNoCopy3.Length == args.Length) { if (array3[0] != null) { object[] array5 = new object[parametersNoCopy3.Length]; int num5 = parametersNoCopy3.Length - 1; Array.Copy(args, 0, array5, 0, num5); array5[num5] = Array.UnsafeCreateInstance(array3[0], 1); ((Array)array5[num5]).SetValue(args[num5], 0); args = array5; } } else if (parametersNoCopy3.Length > args.Length) { object[] array6 = new object[parametersNoCopy3.Length]; int i; for (i = 0; i < args.Length; i++) { array6[i] = args[i]; } while (i < parametersNoCopy3.Length - 1) { array6[i] = parametersNoCopy3[i].DefaultValue; i++; } if (array3[0] != null) { array6[i] = Array.UnsafeCreateInstance(array3[0], 0); } else { array6[i] = parametersNoCopy3[i].DefaultValue; } args = array6; } else if ((array[0].CallingConvention & CallingConventions.VarArgs) == (CallingConventions)0) { object[] array7 = new object[parametersNoCopy3.Length]; int num6 = parametersNoCopy3.Length - 1; Array.Copy(args, 0, array7, 0, num6); array7[num6] = Array.UnsafeCreateInstance(array3[0], args.Length - num6); Array.Copy(args, num6, (Array)array7[num6], 0, args.Length - num6); args = array7; } return(array[0]); } int num7 = 0; bool flag2 = false; for (int i = 1; i < num; i++) { int num8 = DefaultBinder.FindMostSpecificMethod(array[num7], array2[num7], array3[num7], array[i], array2[i], array3[i], array4, args); if (num8 == 0) { flag2 = true; } else if (num8 == 2) { num7 = i; flag2 = false; } } if (flag2) { throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException")); } if (names != null) { state = new DefaultBinder.BinderState((int[])array2[num7].Clone(), args.Length, array3[num7] != null); DefaultBinder.ReorderParams(array2[num7], args); } ParameterInfo[] parametersNoCopy4 = array[num7].GetParametersNoCopy(); if (parametersNoCopy4.Length == args.Length) { if (array3[num7] != null) { object[] array8 = new object[parametersNoCopy4.Length]; int num9 = parametersNoCopy4.Length - 1; Array.Copy(args, 0, array8, 0, num9); array8[num9] = Array.UnsafeCreateInstance(array3[num7], 1); ((Array)array8[num9]).SetValue(args[num9], 0); args = array8; } } else if (parametersNoCopy4.Length > args.Length) { object[] array9 = new object[parametersNoCopy4.Length]; int i; for (i = 0; i < args.Length; i++) { array9[i] = args[i]; } while (i < parametersNoCopy4.Length - 1) { array9[i] = parametersNoCopy4[i].DefaultValue; i++; } if (array3[num7] != null) { array9[i] = Array.UnsafeCreateInstance(array3[num7], 0); } else { array9[i] = parametersNoCopy4[i].DefaultValue; } args = array9; } else if ((array[num7].CallingConvention & CallingConventions.VarArgs) == (CallingConventions)0) { object[] array10 = new object[parametersNoCopy4.Length]; int num10 = parametersNoCopy4.Length - 1; Array.Copy(args, 0, array10, 0, num10); array10[num10] = Array.UnsafeCreateInstance(array3[num7], args.Length - num10); Array.Copy(args, num10, (Array)array10[num10], 0, args.Length - num10); args = array10; } return(array[num7]); }
public override MethodBase BindToMethod(BindingFlags bindingAttr, MethodBase[] match, ref object[] args, ParameterModifier[] modifiers, CultureInfo cultureInfo, string[] names, out object state) { if (match == null || match.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), "match"); } MethodBase[] methodBaseArray = (MethodBase[])match.Clone(); state = (object)null; int[][] numArray = new int[methodBaseArray.Length][]; for (int index1 = 0; index1 < methodBaseArray.Length; ++index1) { ParameterInfo[] parametersNoCopy = methodBaseArray[index1].GetParametersNoCopy(); numArray[index1] = new int[parametersNoCopy.Length > args.Length ? parametersNoCopy.Length : args.Length]; if (names == null) { for (int index2 = 0; index2 < args.Length; ++index2) { numArray[index1][index2] = index2; } } else if (!DefaultBinder.CreateParamOrder(numArray[index1], parametersNoCopy, names)) { methodBaseArray[index1] = (MethodBase)null; } } Type[] typeArray = new Type[methodBaseArray.Length]; Type[] types = new Type[args.Length]; for (int index = 0; index < args.Length; ++index) { if (args[index] != null) { types[index] = args[index].GetType(); } } int index3 = 0; bool flag1 = (uint)(bindingAttr & BindingFlags.OptionalParamBinding) > 0U; for (int index1 = 0; index1 < methodBaseArray.Length; ++index1) { Type type1 = (Type)null; if (!(methodBaseArray[index1] == (MethodBase)null)) { ParameterInfo[] parametersNoCopy = methodBaseArray[index1].GetParametersNoCopy(); if (parametersNoCopy.Length == 0) { if (args.Length == 0 || (methodBaseArray[index1].CallingConvention & CallingConventions.VarArgs) != (CallingConventions)0) { numArray[index3] = numArray[index1]; methodBaseArray[index3++] = methodBaseArray[index1]; } } else { if (parametersNoCopy.Length > args.Length) { int length = args.Length; while (length < parametersNoCopy.Length - 1 && parametersNoCopy[length].DefaultValue != DBNull.Value) { ++length; } if (length == parametersNoCopy.Length - 1) { if (parametersNoCopy[length].DefaultValue == DBNull.Value) { if (parametersNoCopy[length].ParameterType.IsArray && parametersNoCopy[length].IsDefined(typeof(ParamArrayAttribute), true)) { type1 = parametersNoCopy[length].ParameterType.GetElementType(); } else { continue; } } } else { continue; } } else if (parametersNoCopy.Length < args.Length) { int index2 = parametersNoCopy.Length - 1; if (parametersNoCopy[index2].ParameterType.IsArray && parametersNoCopy[index2].IsDefined(typeof(ParamArrayAttribute), true) && numArray[index1][index2] == index2) { type1 = parametersNoCopy[index2].ParameterType.GetElementType(); } else { continue; } } else { int index2 = parametersNoCopy.Length - 1; if (parametersNoCopy[index2].ParameterType.IsArray && parametersNoCopy[index2].IsDefined(typeof(ParamArrayAttribute), true) && (numArray[index1][index2] == index2 && !parametersNoCopy[index2].ParameterType.IsAssignableFrom(types[index2]))) { type1 = parametersNoCopy[index2].ParameterType.GetElementType(); } } int num = type1 != (Type)null ? parametersNoCopy.Length - 1 : args.Length; int index4; for (index4 = 0; index4 < num; ++index4) { Type type2 = parametersNoCopy[index4].ParameterType; if (type2.IsByRef) { type2 = type2.GetElementType(); } if (!(type2 == types[numArray[index1][index4]]) && (!flag1 || args[numArray[index1][index4]] != Type.Missing) && (args[numArray[index1][index4]] != null && !(type2 == typeof(object)))) { if (type2.IsPrimitive) { if (types[numArray[index1][index4]] == (Type)null || !DefaultBinder.CanConvertPrimitiveObjectToType(args[numArray[index1][index4]], (RuntimeType)type2)) { break; } } else if (!(types[numArray[index1][index4]] == (Type)null) && !type2.IsAssignableFrom(types[numArray[index1][index4]]) && (!types[numArray[index1][index4]].IsCOMObject || !type2.IsInstanceOfType(args[numArray[index1][index4]]))) { break; } } } if (type1 != (Type)null && index4 == parametersNoCopy.Length - 1) { for (; index4 < args.Length; ++index4) { if (type1.IsPrimitive) { if (types[index4] == (Type)null || !DefaultBinder.CanConvertPrimitiveObjectToType(args[index4], (RuntimeType)type1)) { break; } } else if (!(types[index4] == (Type)null) && !type1.IsAssignableFrom(types[index4]) && (!types[index4].IsCOMObject || !type1.IsInstanceOfType(args[index4]))) { break; } } } if (index4 == args.Length) { numArray[index3] = numArray[index1]; typeArray[index3] = type1; methodBaseArray[index3++] = methodBaseArray[index1]; } } } } if (index3 == 0) { throw new MissingMethodException(Environment.GetResourceString("MissingMember")); } if (index3 == 1) { if (names != null) { state = (object)new DefaultBinder.BinderState((int[])numArray[0].Clone(), args.Length, typeArray[0] != (Type)null); DefaultBinder.ReorderParams(numArray[0], args); } ParameterInfo[] parametersNoCopy = methodBaseArray[0].GetParametersNoCopy(); if (parametersNoCopy.Length == args.Length) { if (typeArray[0] != (Type)null) { object[] objArray = new object[parametersNoCopy.Length]; int length = parametersNoCopy.Length - 1; Array.Copy((Array)args, 0, (Array)objArray, 0, length); objArray[length] = (object)Array.UnsafeCreateInstance(typeArray[0], 1); ((Array)objArray[length]).SetValue(args[length], 0); args = objArray; } } else if (parametersNoCopy.Length > args.Length) { object[] objArray = new object[parametersNoCopy.Length]; int index1; for (index1 = 0; index1 < args.Length; ++index1) { objArray[index1] = args[index1]; } for (; index1 < parametersNoCopy.Length - 1; ++index1) { objArray[index1] = parametersNoCopy[index1].DefaultValue; } objArray[index1] = !(typeArray[0] != (Type)null) ? parametersNoCopy[index1].DefaultValue : (object)Array.UnsafeCreateInstance(typeArray[0], 0); args = objArray; } else if ((methodBaseArray[0].CallingConvention & CallingConventions.VarArgs) == (CallingConventions)0) { object[] objArray = new object[parametersNoCopy.Length]; int index1 = parametersNoCopy.Length - 1; Array.Copy((Array)args, 0, (Array)objArray, 0, index1); objArray[index1] = (object)Array.UnsafeCreateInstance(typeArray[0], args.Length - index1); Array.Copy((Array)args, index1, (Array)objArray[index1], 0, args.Length - index1); args = objArray; } return(methodBaseArray[0]); } int index5 = 0; bool flag2 = false; for (int index1 = 1; index1 < index3; ++index1) { switch (DefaultBinder.FindMostSpecificMethod(methodBaseArray[index5], numArray[index5], typeArray[index5], methodBaseArray[index1], numArray[index1], typeArray[index1], types, args)) { case 0: flag2 = true; break; case 2: index5 = index1; flag2 = false; break; } } if (flag2) { throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException")); } if (names != null) { state = (object)new DefaultBinder.BinderState((int[])numArray[index5].Clone(), args.Length, typeArray[index5] != (Type)null); DefaultBinder.ReorderParams(numArray[index5], args); } ParameterInfo[] parametersNoCopy1 = methodBaseArray[index5].GetParametersNoCopy(); if (parametersNoCopy1.Length == args.Length) { if (typeArray[index5] != (Type)null) { object[] objArray = new object[parametersNoCopy1.Length]; int length = parametersNoCopy1.Length - 1; Array.Copy((Array)args, 0, (Array)objArray, 0, length); objArray[length] = (object)Array.UnsafeCreateInstance(typeArray[index5], 1); ((Array)objArray[length]).SetValue(args[length], 0); args = objArray; } } else if (parametersNoCopy1.Length > args.Length) { object[] objArray = new object[parametersNoCopy1.Length]; int index1; for (index1 = 0; index1 < args.Length; ++index1) { objArray[index1] = args[index1]; } for (; index1 < parametersNoCopy1.Length - 1; ++index1) { objArray[index1] = parametersNoCopy1[index1].DefaultValue; } objArray[index1] = !(typeArray[index5] != (Type)null) ? parametersNoCopy1[index1].DefaultValue : (object)Array.UnsafeCreateInstance(typeArray[index5], 0); args = objArray; } else if ((methodBaseArray[index5].CallingConvention & CallingConventions.VarArgs) == (CallingConventions)0) { object[] objArray = new object[parametersNoCopy1.Length]; int index1 = parametersNoCopy1.Length - 1; Array.Copy((Array)args, 0, (Array)objArray, 0, index1); objArray[index1] = (object)Array.UnsafeCreateInstance(typeArray[index5], args.Length - index1); Array.Copy((Array)args, index1, (Array)objArray[index1], 0, args.Length - index1); args = objArray; } return(methodBaseArray[index5]); }