Пример #1
0
        internal protected override void RenderNode(WordTemplateParameters p)
        {
            object obj  = ValueProvider.GetValue(p);
            string text = obj is Enum ? ((Enum)obj).NiceToString() :
                          obj is IFormattable ? ((IFormattable)obj).ToString(Format ?? ValueProvider.Format, p.Culture) :
                          obj?.ToString();

            this.ReplaceBy(this.NodeProvider.NewRun((OpenXmlCompositeElement)this.RunProperties?.CloneNode(true), text));
        }
            public override void PrintList(EmailTemplateParameters p)
            {
                var obj = ValueProvider.GetValue(p);

                var text = obj is Enum ? ((Enum)obj).NiceToString() :
                           obj is IFormattable ? ((IFormattable)obj).ToString(Format ?? ValueProvider.Format, p.Culture) :
                           obj?.ToString();

                p.StringBuilder.Append(p.IsHtml && !IsRaw && !(obj is HtmlString)? HttpUtility.HtmlEncode(text) : text);
            }
Пример #3
0
        internal protected override void RenderNode(WordTemplateParameters p)
        {
            object?obj  = ValueProvider.GetValue(p);
            string?text = obj is Enum en?en.NiceToString() :
                              obj is IFormattable fo?fo.ToString(Format ?? ValueProvider.Format, p.Culture) :
                                  obj?.ToString();

            if (text != null && text.Contains('\n'))
            {
                var replacements = text.Lines().Select((line, i) => this.NodeProvider.NewRun((OpenXmlCompositeElement?)this.RunProperties?.CloneNode(true), line, initialBr: i > 0));

                this.ReplaceBy(replacements);
            }
            else
            {
                this.ReplaceBy(this.NodeProvider.NewRun((OpenXmlCompositeElement?)this.RunProperties?.CloneNode(true), text));
            }
        }
Пример #4
0
        protected internal override void RenderNode(WordTemplateParameters p)
        {
            var obj = ValueProvider.GetValue(p);

            string text;

            switch (obj)
            {
            case Enum e:
                text = e.NiceToString();
                break;

            case bool b:
                text = b ? BooleanEnum.True.NiceToString() : BooleanEnum.False.NiceToString();
                break;

            case IFormattable f:
                text = f.ToString(Format ?? ValueProvider.Format, p.Culture);
                break;

            default:
                text = obj?.ToString();
                break;
            }

            if (text != null && text.Contains('\n'))
            {
                var replacements = text.Lines()
                                   .Select((line, i) => NodeProvider.NewRun((OpenXmlCompositeElement)RunProperties?.CloneNode(true), line, initialBr: i > 0));

                this.ReplaceBy(replacements);
            }
            else
            {
                this.ReplaceBy(NodeProvider.NewRun((OpenXmlCompositeElement)RunProperties?.CloneNode(true), text));
            }
        }