antlr / stringtemplate4

StringTemplate 4
http://www.stringtemplate.org
Other
956 stars 231 forks source link

StringTemplate4 (.Net) cloned templates (shadow) work only once, subsequent calls render empty values #176

Open lafar6502 opened 7 years ago

lafar6502 commented 7 years ago

Registered also as https://github.com/antlr/antlrcs/issues/72

Here is a failing test First template (t0) created with 'CreateShadow' works OK Second (t1) does not, renders all model values as empty ST4.0.8

`public class Test { public string Name { get; set; } public Test Parent { get; set; } public string Title; public decimal Age { get; set; } public DateTime CreatedDate;

        public Test()
        {
            Name = "name of test";
            Title = "titel titel";
            Age = 198.88m;
            CreatedDate = DateTime.Now;
        }
    }

    [TestMethod]
    public void ReuseTemplateTest()
    {
        //temp\sttest is empty dir, just for test
        var stg = new TemplateRawGroupDirectory("c:\\temp\\sttest", '$', '$');

        var tpl = new Template(stg, "$model.Name$ $model.Title$");
        var mdl = new Test { Name = "zzzyzx", Title = "mmm" };
        var t0 = tpl.CreateShadow();
        t0.Add("model", mdl);
        var txt0 = t0.Render();
        Assert.IsTrue(txt0.Contains(mdl.Title) && txt0.Contains(mdl.Name));

        var t1 = tpl.CreateShadow();
        t1.Add("model", mdl);
        var txt1 = t1.Render();
        Assert.IsTrue(txt1.Contains(mdl.Title) && txt1.Contains(mdl.Name));
    }`