Пример #1
0
        /// <summary>
        ///     Executes the specified formatter.
        /// </summary>
        /// <param name="formatter">The formatter.</param>
        /// <param name="sourceObject">The source object.</param>
        /// <param name="templateArguments">The template arguments.</param>
        /// <returns></returns>
        public virtual async Task <object> Execute(FormatTemplateElement formatter,
                                                   object sourceObject,
                                                   params KeyValuePair <string, object>[] templateArguments)
        {
            var values = ComposeValues(formatter, sourceObject, templateArguments);

            if (values == null)
            {
                Log(() => "Skip: Execute skip as Compose Values returned an invalid value");
                return(FormatterFlow.Skip);
            }

            if (formatter.CanFormat != null)
            {
                if (!formatter.CanFormat(sourceObject, templateArguments))
                {
                    Log(() => "Skip: Execute skip as CanExecute is false.");
                    return(FormatterFlow.Skip);
                }
            }

            Log(() => $"Execute");
            var taskAlike = formatter.Format.DynamicInvoke(values.Select(e => e.Value).ToArray());

            return(await taskAlike.UnpackFormatterTask());
        }
Пример #2
0
        /// <summary>
        ///     Executes the specified formatter.
        /// </summary>
        /// <param name="formatter">The formatter.</param>
        /// <param name="sourceObject">The source object.</param>
        /// <param name="templateArguments">The template arguments.</param>
        /// <returns></returns>
        public virtual object Execute([NotNull] FormatTemplateElement formatter,
                                      [CanBeNull] object sourceObject,
                                      params KeyValuePair <string, object>[] templateArguments)
        {
            var values = ComposeValues(formatter, sourceObject, templateArguments);

            if (values == null)
            {
                Write(() => "Skip: Execute skip as Compose Values returned an invalid value");
                return(FormatterFlow.Skip);
            }

            if (formatter.CanFormat != null)
            {
                if (!formatter.CanFormat(sourceObject, templateArguments))
                {
                    Write(() => "Skip: Execute skip as CanExecute is false.");
                    return(FormatterFlow.Skip);
                }
            }

            Write(() => $"Execute");
            return(formatter.Format.DynamicInvoke(values.Select(e => e.Value).ToArray()));
        }