C#DotLiquid简单示例单元测试未按预期工作

Tre*_*fex 3 c# template-engine .net-4.0 liquid

我一直想要使用伟大的DotLiquid并尝试遵循示例(由我自己编写)而没有任何重大成功.

internal class AuthorDrop : Drop {
    private String lname;

    public String ToGive { get { return lname; } }


    public AuthorDrop(String t) {
        lname = t;
    }
}
Run Code Online (Sandbox Code Playgroud)

与相应的测试

[Test]
    public void TestFirstStep() {
       Template tpl = Template.Parse("hi {{ author2.togive }}");  
       Console.WriteLine(tpl.Render(Hash.FromAnonymousObject(new { author2 = new AuthorDrop("Test 123") }))); 
    }
Run Code Online (Sandbox Code Playgroud)

然而,这有助于产出

而不是喜测试123.

任何人都可以帮我弄清楚这里发生了什么?

非常感谢你提前,

- 克里斯

小智 10

默认情况下,DotLiquid使用Ruby的方法和属性命名约定.在您的示例中,ToGive被"重命名"为to_give.如果您愿意,可以通过设置静态属性来使用C#命名约定DotLiquid.Template.NamingConvention = new DotLiquid.NamingConventions.CSharpNamingConvention();

HTH