public override MethodBase BindToMethod(BindingFlags bindingAttr, MethodBase[] match, ref object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] names, out object state)
#endif
{
try {
var nativeResult = _binder.BindToMethod(bindingAttr, match, ref args, modifiers, culture, names, out state);
if (nativeResult != null)
{
return(nativeResult);
}
} catch (MissingMemberException) {
// ignore
}
var argumentTypes = args.Select(a => a == null ? typeof(Object) : a.GetType()).ToArray();
state = new Object(); // ???
var result = SelectMethod(bindingAttr, match, argumentTypes, modifiers);
if (result != null)
{
var parameters = result.GetParameters();
for (int i = 0; i < args.Length; i++)
{
// this is assumed to work at this point. a situation where
// we could not convert the argument types should not have
// bound and SelectMethod should have returned null
if (parameters[i].ParameterType.IsEnum)
{
args[i] = Enum.ToObject(parameters[i].ParameterType, args[i]);
}
else
{
args[i] = Convert.ChangeType(args[i], parameters[i].ParameterType);
}
}
}
return(result);
}