-
- /// <summary>
- /// Verifies whether the method in question is compatible with the delegate
- /// Returns the method itself if okay and null if not.
- /// </summary>
- public static MethodBase VerifyMethod (Type container_type, Type delegate_type,
- MethodGroupExpr old_mg, MethodBase mb)
- {
- MethodInfo invoke_mb = GetInvokeMethod (container_type, delegate_type);
- if (invoke_mb == null)
- return null;
-
- ParameterData invoke_pd = TypeManager.GetParameterData (invoke_mb);
-
-#if GMCS_SOURCE
- if (old_mg.type_arguments == null &&
- !TypeManager.InferTypeArguments (invoke_pd, ref mb))
- return null;
-#endif
-
- ParameterData pd = TypeManager.GetParameterData (mb);
-
- if (invoke_pd.Count != pd.Count)
- return null;
-
- for (int i = pd.Count; i > 0; ) {
- i--;
-
- Type invoke_pd_type = invoke_pd.ParameterType (i);
- Type pd_type = pd.ParameterType (i);
- Parameter.Modifier invoke_pd_type_mod = invoke_pd.ParameterModifier (i);
- Parameter.Modifier pd_type_mod = pd.ParameterModifier (i);
-
- invoke_pd_type_mod &= ~Parameter.Modifier.PARAMS;
- pd_type_mod &= ~Parameter.Modifier.PARAMS;
-
- if (invoke_pd_type_mod != pd_type_mod)
- return null;
-
- if (invoke_pd_type == pd_type)
- continue;
-
- //if (!IsTypeCovariant (invoke_pd_type, pd_type))
- // return null;
-
- if (RootContext.Version == LanguageVersion.ISO_1)
- return null;
- }
-
- Type invoke_mb_retval = ((MethodInfo) invoke_mb).ReturnType;
- Type mb_retval = ((MethodInfo) mb).ReturnType;
- if (TypeManager.TypeToCoreType (invoke_mb_retval) == TypeManager.TypeToCoreType (mb_retval))
- return mb;
-
- //if (!IsTypeCovariant (mb_retval, invoke_mb_retval))
- // return null;
-
- if (RootContext.Version == LanguageVersion.ISO_1)
- return null;
-
- return mb;
- }
-
- // <summary>
- // Verifies whether the invocation arguments are compatible with the
- // delegate's target method
- // </summary>
- public static bool VerifyApplicability (EmitContext ec, Type delegate_type,
- ArrayList args, Location loc)
- {
- int arg_count;
-
- if (args == null)
- arg_count = 0;
- else
- arg_count = args.Count;
-
- Expression ml = Expression.MemberLookup (
- ec.ContainerType, delegate_type, "Invoke", loc);
-
- MethodGroupExpr me = ml as MethodGroupExpr;
- if (me == null) {
- Report.Error (-100, loc, "Internal error: could not find Invoke method!" + delegate_type);
- return false;
- }
-
- MethodBase mb = GetInvokeMethod (ec.ContainerType, delegate_type);
- ParameterData pd = TypeManager.GetParameterData (mb);
-
- int pd_count = pd.Count;
-
- bool params_method = pd.HasParams;
- bool is_params_applicable = false;
- me.DelegateType = delegate_type;
- bool is_applicable = me.IsApplicable (ec, args, arg_count, ref mb, ref is_params_applicable) == 0;