- public bool IsParamsMethodApplicable (EmitContext ec,
- ArrayList arguments, int arg_count,
- ref MethodBase candidate)
- {
- return IsParamsMethodApplicable (
- ec, arguments, arg_count, false, ref candidate) ||
- IsParamsMethodApplicable (
- ec, arguments, arg_count, true, ref candidate);
-
-
- }
-
- bool IsParamsMethodApplicable (EmitContext ec,
- ArrayList arguments, int arg_count,
- bool do_varargs, ref MethodBase candidate)
- {
-#if GMCS_SOURCE
- if (!HasTypeArguments &&
- !TypeManager.InferParamsTypeArguments (ec, arguments, ref candidate))
- return false;
-
- if (TypeManager.IsGenericMethodDefinition (candidate))
- throw new InternalErrorException ("a generic method definition took part in overload resolution");
-#endif
-
- return IsParamsMethodApplicable (
- ec, arguments, arg_count, candidate, do_varargs);
- }
-
- /// <summary>
- /// Determines if the candidate method, if a params method, is applicable
- /// in its expanded form to the given set of arguments
- /// </summary>
- bool IsParamsMethodApplicable (EmitContext ec, ArrayList arguments,
- int arg_count, MethodBase candidate,
- bool do_varargs)
- {
- ParameterData pd = TypeManager.GetParameterData (candidate);
- int pd_count = GetApplicableParametersCount (candidate, pd);
- if (pd_count == 0)
- return false;
-
- int count = pd_count - 1;
- if (do_varargs) {
- if (pd.ParameterModifier (count) != Parameter.Modifier.ARGLIST)
- return false;
- if (pd_count != arg_count)
- return false;
-
- if (!(((Argument) arguments [count]).Expr is Arglist))
- return false;
- --pd_count;
- } else {
- if (!pd.HasParams)
- return false;
- }
-
- if (count > arg_count)
- return false;
-
- if (pd_count == 1 && arg_count == 0)
- return true;
-
- //
- // If we have come this far, the case which
- // remains is when the number of parameters is
- // less than or equal to the argument count.
- //
- int argument_index = 0;
- Argument a;
- for (int i = 0; i < pd_count; ++i) {
-
- if ((pd.ParameterModifier (i) & Parameter.Modifier.PARAMS) != 0) {
- Type element_type = TypeManager.GetElementType (pd.ParameterType (i));
- int params_args_count = arg_count - pd_count;
- if (params_args_count < 0)
- continue;
-
- do {
- a = (Argument) arguments [argument_index++];
-
- if (!Convert.ImplicitConversionExists (ec, a.Expr, element_type))
- return false;
- } while (params_args_count-- > 0);
- continue;
- }
-
- a = (Argument) arguments [argument_index++];
-
- Parameter.Modifier a_mod = a.Modifier &
- (unchecked (~(Parameter.Modifier.OUTMASK | Parameter.Modifier.REFMASK)));
- Parameter.Modifier p_mod = pd.ParameterModifier (i) &
- (unchecked (~(Parameter.Modifier.OUTMASK | Parameter.Modifier.REFMASK)));
-
- if (a_mod == p_mod) {
-
- if (a_mod == Parameter.Modifier.NONE)
- if (!Convert.ImplicitConversionExists (ec,
- a.Expr,
- pd.ParameterType (i)))
- return false;
-
- if ((a_mod & Parameter.Modifier.ISBYREF) != 0) {
- Type pt = pd.ParameterType (i);
-
- if (!pt.IsByRef)
- pt = TypeManager.GetReferenceType (pt);
-
- if (pt != a.Type)
- return false;
- }
- } else
- return false;
-
- }
-
- return true;
- }
-