Пример #1
0
        /// <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);
        }