/// <summary>
        /// Invoke the best available match (from a list of methods available) for the supplied parameters.
        /// If no method can be called using the supplied parameters, an exception is raised. Any exceptions
        /// raised by the called method will be logged and then re-thrown.
        /// </summary>
        /// <param name="target">The object on which to invoke a method.</param>
        /// <param name="parameters">A hashtable of parameter name/value pairs. All parameters given
        /// must be used in the method call in order for a method to be considered.</param>
        /// <returns>The return value of the invocation.</returns>
        public object Invoke(object target, Hashtable parameters)
        {
            MethodInvokable invokable = DetermineBestMatch(parameters);

            Check.VerifyNotNull(invokable, Error.DeveloperError, "No compatible method found to invoke for the given parameters.");
            return(invokable.Invoke(target));
        }
Beispiel #2
0
        /// <summary>
        /// Invoke the underlying method on the given target object using the supplied parameter values.
        /// Any exception raised by performing the method call is logged and then exposed as-is.
        /// </summary>
        /// <param name="target">The object on which to invoke the method.</param>
        /// <param name="parameters">A hashtable of parameter name/value pairs.</param>
        /// <returns>The return value of the invocation.</returns>
        public object Invoke(object target, Hashtable parameters)
        {
            MethodInvokable mi = PrepareInvoke(parameters);

            if (mi.MatchIndicator >= 0)
            {
                return(Invoke(target, mi.ParameterValues));
            }
            else
            {
                Check.Fail(Error.DeveloperError, "Unable to invoke method using given parameters.");
                return(null);
            }
        }
        private MethodInvokable DetermineBestMatch(Hashtable parameters)
        {
            MethodInvokable best = null;

            foreach (MethodInvoker invoker in invokers)
            {
                MethodInvokable invokable = invoker.PrepareInvoke(parameters);
                bool            isBetter  = best == null && invokable != null && invokable.MatchIndicator > 0;
                isBetter |= best != null && invokable != null && invokable.MatchIndicator > best.MatchIndicator;
                if (isBetter)
                {
                    best = invokable;
                }
            }
            return(best);
        }