MethodBase SelectMethod (BindingFlags bindingAttr, MethodBase[] match, Type[] types, ParameterModifier[] modifiers, bool allowByRefMatch)
{
MethodBase m;
int i, j;
if (match == null)
throw new ArgumentNullException ("match");
/* first look for an exact match... */
for (i = 0; i < match.Length; ++i) {
m = match [i];
ParameterInfo[] args = m.GetParameters ();
if (args.Length != types.Length)
continue;
for (j = 0; j < types.Length; ++j) {
if (types [j] != args [j].ParameterType)
break;
}
if (j == types.Length)
return m;
}
/* Try methods with ParamArray attribute */
bool isdefParamArray = false;
Type elementType = null;
for (i = 0; i < match.Length; ++i) {
m = match [i];
ParameterInfo[] args = m.GetParameters ();
if (args.Length > types.Length)
continue;
else if (args.Length == 0)
continue;
isdefParamArray = Attribute.IsDefined (args [args.Length - 1], typeof (ParamArrayAttribute));
if (!isdefParamArray)
continue;
elementType = args [args.Length - 1].ParameterType.GetElementType ();
for (j = 0; j < types.Length; ++j) {
if (j < (args.Length - 1) && types [j] != args [j].ParameterType)
break;
else if (j >= (args.Length - 1) && types [j] != elementType)
break;
}
if (j == types.Length)
return m;
}
if ((int)(bindingAttr & BindingFlags.ExactBinding) != 0)
return null;
MethodBase result = null;
for (i = 0; i < match.Length; ++i) {
m = match [i];
ParameterInfo[] args = m.GetParameters ();
if (args.Length != types.Length)
continue;
if (!check_arguments (types, args, allowByRefMatch))
continue;
if (result != null)
result = GetBetterMethod (result, m, types);
else
result = m;
}
return result;
}