Beispiel #1
0
        /// <summary>
        /// Override the parameters values using the given collection of list text builders where the key
        /// is the parameter name and the selected builder's output is the parameter value
        /// </summary>
        /// <param name="paramsValues"></param>
        public ParametricTextComposer SetParametersValues(IParametricTextComposerValueSource paramsValues)
        {
            foreach (var paramName in _parameters.Keys)
            {
                if (paramsValues.TryGetParameterValue(paramName, out var paramValue))
                {
                    this[paramName] = paramValue;
                }
            }

            return(this);
        }
        /// <summary>
        /// Generate the given template text from the supplied parameters values
        /// </summary>
        /// <param name="composer"></param>
        /// <param name="paramsValues"></param>
        /// <returns></returns>
        public static string GenerateText(this ParametricTextComposer composer, IParametricTextComposerValueSource paramsValues)
        {
            composer.SetParametersValues(paramsValues);

            return(composer.GenerateText());
        }
 /// <summary>
 /// Apply the given parameters values to all templates in this collection and generate text from
 /// each template based on the given parameters. This should be used if all templates use common
 /// or similar set of parameters
 /// </summary>
 /// <param name="composer"></param>
 /// <param name="paramsValues"></param>
 /// <returns></returns>
 public static Dictionary <string, string> GenerateText(this ParametricTextComposerCollection composer, IParametricTextComposerValueSource paramsValues)
 {
     return
         (composer
          .ToDictionary(
              pair => pair.Key,
              pair => pair.Value.GenerateText(paramsValues)
              ));
 }
        public static LinearTextComposer AppendNewLine(this LinearTextComposer textBuilder, ParametricTextComposer template, IParametricTextComposerValueSource parametersValues)
        {
            var text = template.GenerateText(parametersValues);

            return(textBuilder.AppendNewLine(text));
        }
        /// <summary>
        /// Generate the given template text from the supplied parameters values and add its output to
        /// the given text builder at the given index
        /// </summary>
        /// <param name="textBuilder"></param>
        /// <param name="index"></param>
        /// <param name="template"></param>
        /// <param name="paramsValues"></param>
        public static void Insert(this ListTextComposer textBuilder, int index, ParametricTextComposer template, IParametricTextComposerValueSource paramsValues)
        {
            template.SetParametersValues(paramsValues);

            var text = template.GenerateText();

            textBuilder.Insert(index, new StructuredTextItem(text));
        }
        /// <summary>
        /// Generate the given template text from the supplied parameters values and add its output to
        /// the given text builder
        /// </summary>
        /// <param name="textBuilder"></param>
        /// <param name="template"></param>
        /// <param name="paramsValues"></param>
        public static void Add(this ListTextComposer textBuilder, ParametricTextComposer template, IParametricTextComposerValueSource paramsValues)
        {
            template.SetParametersValues(paramsValues);

            var text = template.GenerateText();

            textBuilder.Add(text);
        }
        /// <summary>
        /// Generate a dictionary of names-values and add the values in the dictionary to the given text
        /// builders collection
        /// </summary>
        /// <param name="textBuilder"></param>
        /// <param name="templates"></param>
        /// <param name="paramsValues"></param>
        public static ListComposerCollection AddTextItems(this ListComposerCollection textBuilder, ParametricTextComposerCollection templates, IParametricTextComposerValueSource paramsValues)
        {
            foreach (var pair in textBuilder)
            {
                if (templates.TryGetValue(pair.Key, out var template))
                {
                    pair.Value.Add(template, paramsValues);
                }
            }

            return(textBuilder);
        }