Exemple #1
0
        /// <summary>
        ///     Parses the current object by using the given argument
        /// </summary>
        public async Task <object> Format(string name, KeyValuePair <string, object>[] argument)
        {
            await EnsureValue();

            var retval = Value;

            if (Value == null)
            {
                return(retval);
            }

            if (string.IsNullOrWhiteSpace(name))
            {
                name = null;
            }

            //call formatters that are given by the Options for this run
            retval = await Options.Formatters.CallMostMatchingFormatter(Value.GetType(), argument, Value, name);

            if (!Equals(retval, MorestachioFormatterService.FormatterFlow.Skip))
            {
                //one formatter has returned a valid value so use this one.
                return(retval);
            }

            //all formatters in the options object have rejected the value so try use the global ones
            retval = await DefaultFormatter.CallMostMatchingFormatter(Value.GetType(), argument, Value, name);

            if (!Equals(retval, MorestachioFormatterService.FormatterFlow.Skip))
            {
                return(retval);
            }
            return(Value);
        }
Exemple #2
0
        /// <summary>
        ///     Parses the current object by using the given argument
        /// </summary>
        /// <param name="argument"></param>
        /// <returns></returns>
        public async Task <object> Format(KeyValuePair <string, object>[] argument)
        {
            await EnsureValue();

            var retval = Value;

            if (Value == null)
            {
                return(retval);
            }

            //call formatters that are given by the Options for this run
            retval = await Options.Formatters.CallMostMatchingFormatter(Value.GetType(), argument, Value);

            if ((retval as FormatterMatcher.FormatterFlow) != FormatterMatcher.FormatterFlow.Skip)
            {
                //one formatter has returned a valid value so use this one.
                return(retval);
            }

            //all formatters in the options object have rejected the value so try use the global ones
            retval = await DefaultFormatter.CallMostMatchingFormatter(Value.GetType(), argument, Value);

            if ((retval as FormatterMatcher.FormatterFlow) != FormatterMatcher.FormatterFlow.Skip)
            {
                return(retval);
            }
            return(Value);
        }
Exemple #3
0
        public async Task <object> Format(KeyValuePair <string, object>[] argument)
        {
            await EnsureValue();

            var retval = Value;

            if (Value == null)
            {
                return(retval);
            }

            var name = argument.FirstOrDefault().Value?.ToString();
            var argumentWithoutName = argument.Skip(1).ToArray();

            //call formatters that are given by the Options for this run
            retval = await Options.Formatters.CallMostMatchingFormatter(Value.GetType(), argumentWithoutName, Value, name);

            if (!Equals(retval, MorestachioFormatterService.FormatterFlow.Skip))
            {
                //one formatter has returned a valid value so use this one.
                return(retval);
            }

            //call formatters that are given by the Options for this run
            retval = await Options.Formatters.CallMostMatchingFormatter(Value.GetType(), argument, Value, null);

            if (!Equals(retval, MorestachioFormatterService.FormatterFlow.Skip))
            {
                //one formatter has returned a valid value so use this one.
                return(retval);
            }

            //all formatters in the options object have rejected the value so try use the global ones
            retval = await DefaultFormatter.CallMostMatchingFormatter(Value.GetType(), argument, Value, null);

            if (!Equals(retval, MorestachioFormatterService.FormatterFlow.Skip))
            {
                return(retval);
            }
            return(Value);
        }