Esempio n. 1
0
        public void Regression_336()
        {
            var so = new Scriban.Runtime.ScriptObject();

            so.SetValue("X", "TEST", false);
            var evaluated = Template.Parse("{{X}}").Evaluate(new TemplateContext(so));

            //important - test type since ScriptArray can be cast to string implicitly
            Assert.AreEqual(typeof(string), evaluated.GetType());
            Assert.AreEqual("TEST", evaluated);
        }
        public override void Evaluate(TemplateContext context)
        {
            var scriptObject = new ScriptObject();

            foreach (var member in Members)
            {
                var variable = member.Key as ScriptVariable;
                var literal  = member.Key as ScriptLiteral;

                var name = variable?.Name ?? literal?.Value?.ToString();
                scriptObject.SetValue(name, context.Evaluate(member.Value), false);
            }
            context.Result = scriptObject;
        }