Example #1
0
        // <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);
            AParametersCollection pd = TypeManager.GetParameterData(mb);

            int pd_count = pd.Count;

            bool params_method        = pd.HasParams;
            bool is_params_applicable = false;
            bool is_applicable        = me.IsApplicable(ec, args, arg_count, ref mb, ref is_params_applicable) == 0;

            if (!is_applicable && !params_method && arg_count != pd_count)
            {
                Report.Error(1593, loc, "Delegate `{0}' does not take `{1}' arguments",
                             TypeManager.CSharpName(delegate_type), arg_count.ToString());
                return(false);
            }

            return(me.VerifyArgumentsCompat(
                       ec, ref args, arg_count, mb,
                       is_params_applicable || (!is_applicable && params_method),
                       false, loc));
        }
Example #2
0
        // <summary>
        //  Verifies whether the invocation arguments are compatible with the
        //  delegate's target method
        // </summary>
        public static bool VerifyApplicability(ResolveContext ec, Type delegate_type, ref Arguments args, Location loc)
        {
            int arg_count;

            if (args == null)
            {
                arg_count = 0;
            }
            else
            {
                arg_count = args.Count;
            }

            MethodBase      mb = GetInvokeMethod(ec.Compiler, ec.CurrentType, delegate_type);
            MethodGroupExpr me = new MethodGroupExpr(new MemberInfo [] { mb }, delegate_type, loc);

            AParametersCollection pd = TypeManager.GetParameterData(mb);

            int pd_count = pd.Count;

            bool params_method        = pd.HasParams;
            bool is_params_applicable = false;
            bool is_applicable        = me.IsApplicable(ec, ref args, arg_count, ref mb, ref is_params_applicable) == 0;

            if (args != null)
            {
                arg_count = args.Count;
            }

            if (!is_applicable && !params_method && arg_count != pd_count)
            {
                ec.Report.Error(1593, loc, "Delegate `{0}' does not take `{1}' arguments",
                                TypeManager.CSharpName(delegate_type), arg_count.ToString());
                return(false);
            }

            return(me.VerifyArgumentsCompat(
                       ec, ref args, arg_count, mb,
                       is_params_applicable || (!is_applicable && params_method),
                       false, loc));
        }
		// <summary>
		//  Verifies whether the invocation arguments are compatible with the
		//  delegate's target method
		// </summary>
		public static bool VerifyApplicability (ResolveContext ec, Type delegate_type, ref Arguments args, Location loc)
		{
			int arg_count;

			if (args == null)
				arg_count = 0;
			else
				arg_count = args.Count;

			MethodBase mb = GetInvokeMethod (ec.Compiler, ec.CurrentType, delegate_type);
			MethodGroupExpr me = new MethodGroupExpr (new MemberInfo [] { mb }, delegate_type, loc);
			
			AParametersCollection pd = TypeManager.GetParameterData (mb);

			int pd_count = pd.Count;

			bool params_method = pd.HasParams;
			bool is_params_applicable = false;
			bool is_applicable = me.IsApplicable (ec, ref args, arg_count, ref mb, ref is_params_applicable) == 0;
			if (args != null)
				arg_count = args.Count;

			if (!is_applicable && !params_method && arg_count != pd_count) {
				ec.Report.Error (1593, loc, "Delegate `{0}' does not take `{1}' arguments",
					TypeManager.CSharpName (delegate_type), arg_count.ToString ());
				return false;
			}

			return me.VerifyArgumentsCompat (
					ec, ref args, arg_count, mb, 
					is_params_applicable || (!is_applicable && params_method),
					false, loc);
		}
Example #4
0
        protected override Expression DoResolve(ResolveContext ec)
        {
            if (InstanceExpr is EventExpr) {
                ((EventExpr) InstanceExpr).Error_CannotAssign (ec);
                return null;
            }

            TypeSpec del_type = InstanceExpr.Type;
            if (del_type == null)
                return null;

            method = Delegate.GetInvokeMethod (ec.Compiler, del_type);
            var mb = method;
            var me = new MethodGroupExpr (mb, del_type, loc);
            me.InstanceExpression = InstanceExpr;

            AParametersCollection pd = mb.Parameters;
            int pd_count = pd.Count;

            int arg_count = arguments == null ? 0 : arguments.Count;

            bool params_method = pd.HasParams;
            bool is_params_applicable = false;
            bool is_applicable = me.IsApplicable (ec, ref arguments, arg_count, ref mb, ref is_params_applicable) == 0;
            if (arguments != null)
                arg_count = arguments.Count;

            if (!is_applicable && !params_method && arg_count != pd_count) {
                ec.Report.Error (1593, loc, "Delegate `{0}' does not take `{1}' arguments",
                    TypeManager.CSharpName (del_type), arg_count.ToString ());
            } else if (arguments == null || !arguments.HasDynamic) {
                me.VerifyArgumentsCompat (ec, ref arguments, arg_count, mb,
                    is_params_applicable || (!is_applicable && params_method), false, loc);
            }

            type = method.ReturnType;
            eclass = ExprClass.Value;
            return this;
        }