jehugaleahsa / mustache-sharp

An extension of the mustache text template engine for .NET.
The Unlicense
306 stars 80 forks source link

Library doesn't work with dynamic object #78

Open PaulGrimshaw opened 7 years ago

PaulGrimshaw commented 7 years ago

I've written a test to replicate this problem - this would be really useful functionality for us.

        /// <summary>
        /// Testing with Dynamic object.
        /// </summary>
        [TestMethod]
        public void TestCompile_DynamicObject_RendersCorrectly() {
            FormatCompiler compiler = new FormatCompiler();
            const string format = @"Hello {{Name}}";
            Generator generator = compiler.Compile(format);

            dynamic obj = new TestDymnamic();
            Assert.AreEqual("Paul", obj.Name);
            string actual = generator.Render(obj);

            string expected = "Hello Paul";
            Assert.AreEqual(expected, actual, "The number was not passed to the formatter.");
        }

        private class TestDymnamic: DynamicObject {
            public override bool TryGetMember(GetMemberBinder binder, out object result) {
                result = "Paul";
                return true;
            }
        }