private static void ValidateAccessorArgumentTypes(MethodInfo method, ParameterInfo[] indexes, ref ReadOnlyCollection<Expression> arguments, string paramName)
{
if (indexes.Length > 0)
{
if (indexes.Length != arguments.Count)
{
throw Error.IncorrectNumberOfMethodCallArguments(method, paramName);
}
Expression[] newArgs = null;
for (int i = 0, n = indexes.Length; i < n; i++)
{
Expression arg = arguments[i];
ParameterInfo pi = indexes[i];
RequiresCanRead(arg, nameof(arguments), i);
Type pType = pi.ParameterType;
if (pType.IsByRef) throw Error.AccessorsCannotHaveByRefArgs(nameof(indexes), i);
TypeUtils.ValidateType(pType, nameof(indexes), i);
if (!TypeUtils.AreReferenceAssignable(pType, arg.Type))
{
if (!TryQuote(pType, ref arg))
{
throw Error.ExpressionTypeDoesNotMatchMethodParameter(arg.Type, pType, method, nameof(arguments), i);
}
}
if (newArgs == null && arg != arguments[i])
{
newArgs = new Expression[arguments.Count];
for (int j = 0; j < i; j++)
{
newArgs[j] = arguments[j];
}
}
if (newArgs != null)
{
newArgs[i] = arg;
}
}
if (newArgs != null)
{
arguments = new TrueReadOnlyCollection<Expression>(newArgs);
}
}
else if (arguments.Count > 0)
{
throw Error.IncorrectNumberOfMethodCallArguments(method, paramName);
}
}