/// <summary> /// Convert the message template into a textual message, given the /// properties matching the tokens in the message template. /// </summary> /// <param name="properties">Properties matching template tokens.</param> /// <param name="output">The message created from the template and properties. If the /// properties are mismatched with the template, the template will be /// returned with incomplete substitution.</param> /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param> public void Render(TemplatePropertyValueDictionary properties, TextWriter output, IFormatProvider formatProvider = null) { foreach (var token in _tokens) { token.Render(properties, output, formatProvider); } }
/// <summary> /// Convert the message template into a textual message, given the /// properties matching the tokens in the message template. /// </summary> /// <param name="properties">Properties matching template tokens.</param> /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param> /// <returns>The message created from the template and properties. If the /// properties are mismatched with the template, the template will be /// returned with incomplete substitution.</returns> public string Render(TemplatePropertyValueDictionary properties, IFormatProvider formatProvider = null) { var writer = new StringWriter(formatProvider); Render(properties, writer, formatProvider); return(writer.ToString()); }
/// <summary> /// Render the token to the output. /// </summary> /// <param name="properties">Properties that may be represented by the token.</param> /// <param name="output">Output for the rendered string.</param> /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param> public override void Render(TemplatePropertyValueDictionary properties, TextWriter output, IFormatProvider formatProvider = null) { if (output == null) { throw new ArgumentNullException(nameof(output)); } output.Write(Text); }
/// <summary> /// Render the token to the output. /// </summary> /// <param name="properties">Properties that may be represented by the token.</param> /// <param name="output">Output for the rendered string.</param> /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param> public override void Render(TemplatePropertyValueDictionary properties, TextWriter output, IFormatProvider formatProvider = null) { if (properties == null) { throw new ArgumentNullException(nameof(properties)); } if (output == null) { throw new ArgumentNullException(nameof(output)); } TemplatePropertyValue propertyValue; if (!properties.TryGetValue(PropertyName, out propertyValue)) { output.Write(_rawText); return; } if (!Alignment.HasValue) { propertyValue.Render(output, Format, formatProvider); return; } var valueOutput = new StringWriter(); propertyValue.Render(valueOutput, Format, formatProvider); var value = valueOutput.ToString(); if (value.Length >= Alignment.Value.Width) { output.Write(value); return; } Padding.Apply(output, value, Alignment.Value); }
/// <summary> /// Render the token to the output. /// </summary> /// <param name="properties">Properties that may be represented by the token.</param> /// <param name="output">Output for the rendered string.</param> /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param> public abstract void Render( TemplatePropertyValueDictionary properties, TextWriter output, IFormatProvider formatProvider = null);