Exemple #1
0
        /// <summary>
        /// Extracts the value correspondent to the <see cref="KeywordToken"/> from a <see cref="ICommandKeywords"/> and then applies
        /// the extracted value on a string. This method uses the <see cref="FormatValue(ICommandKeywords)"/> method internally to extract
        /// the <see cref="KeywordToken"/> value.
        /// </summary>
        /// <param name="keywords">the <see cref="ICommandKeywords"/> from which the value must be extracted.</param>
        /// <param name="target">the string to apply the extracted value on</param>
        public String ApplyValue(ICommandKeyValues keywords, String target)
        {
            String formatted = FormatValue(keywords);

            target = target.ToString();

            if (formatted == null)
            {
                return(target);
            }

            return(target.Replace(TokenText, formatted));
        }
Exemple #2
0
        /// <summary>
        /// Extracts from a <see cref="ICommandKeywords"/> the value correspondent to the <see cref="KeywordToken"/> and
        /// if the <see cref="KeywordToken"/> has the Parser property set, then, the correspondent <see cref="IValueParser"/> will be used to
        /// parse the value, otherwise, the value will be returned as it is stored in the <see cref="ICommandKeywords"/>.
        /// </summary>
        /// <param name="keywords">the <see cref="ICommandKeywords"/> from which the value must be extracted.</param>
        /// <returns></returns>
        public Object GetValue(ICommandKeyValues keywords)
        {
            if (!keywords.ContainsValue(Name))
            {
                return(null);
            }

            Object value = keywords.GetValue(Name);

            if (Parser != null)
            {
                value = callParser(value, Container);
            }

            return(value);
        }
Exemple #3
0
        /// <summary>
        /// Extracts from a <see cref="ICommandKeywords"/> the value correspondent to the <see cref="KeywordToken"/> and
        /// if the <see cref="KeywordToken"/> has the Formatter property set, then, the correspondent <see cref="IValueFormatter"/> will be used to
        /// format the value, otherwise, the value will be returned as stored in the <see cref="ICommandKeywords"/>.
        /// </summary>
        /// <param name="keywords">the <see cref="ICommandKeywords"/> from which the value must be extracted.</param>
        /// <returns>the extracted and formatted value (if a formatter is set) if found in the <see cref="ICommandKeywords"/> or null if not found</returns>
        public String FormatValue(ICommandKeyValues keywords)
        {
            if (!keywords.ContainsValue(Name))
            {
                return(null);
            }

            Object value = keywords.GetValue(Name);

            if (Formatter != null)
            {
                value = callFormatter(value, Container);
            }

            if (value != null)
            {
                return(value.ToString());
            }

            return("");
        }