示例#1
0
        /// <summary>
        /// Executes this command with the specified <paramref name="parameters"/>. The parameter
        /// enumeration will be automatically converted to the formal parameters of the target method.
        /// <see cref="LateBoundValue"/> instances will be also resolved when used as parameters.
        /// </summary>
        /// <param name="parameters">Enumeration of actual parameters to be used for the command
        /// execution.</param>
        public void Execute(IEnumerable <object> parameters)
        {
            IDataDescriptor start;

            if (!_source.Evaluate(out start))
            {
                ServiceRegistration.Get <ILogger>().Warn("CommandBaseMarkupExtension: Could not find source value, could not execute command ({0})",
                                                         ToString());
                return;
            }
            IList <object> paramsList = LateBoundValue.ConvertLateBoundValues(parameters);
            object         obj;
            MethodInfo     mi;

            _compiledPath.GetMethod(start, paramsList.Count, out obj, out mi);
            if (mi == null)
            {
                ServiceRegistration.Get <ILogger>().Warn("CommandBaseMarkupExtension: Could not find method, could not execute command ({0})",
                                                         ToString());
                return;
            }
            ParameterInfo[] parameterInfos = mi.GetParameters();
            try
            {
                object[] convertedParameters;
                if (ReflectionHelper.ConsumeParameters(paramsList, parameterInfos, true, out convertedParameters))
                {
                    mi.Invoke(obj, convertedParameters);
                }
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Error("CommandBaseMarkupExtension: Error executing command '{0}'", e, this);
            }
        }