开发者

C# DotLiquid Simple Example Unit Test not working as expected

开发者 https://www.devze.com 2023-02-02 23:35 出处:网络
I have been wanting to use the great DotLiquid and tried to following example (written by myself) without any major success.

I have been wanting to use the great DotLiquid and tried to following example (written by myself) without any major success.

internal class AuthorDrop : Drop {
    private String lname;

    public String ToGive { get { return lname; } }


    public AuthorDrop(String t) {
        lname = t;
    }
}

with the corresponding test

[Test]
    public void TestFirstStep() {
       Template tpl = Template开发者_开发知识库.Parse("hi {{ author2.togive }}");  
       Console.WriteLine(tpl.Render(Hash.FromAnonymousObject(new { author2 = new AuthorDrop("Test 123") }))); 
    }

However, this leades to the output

hi

instead of hi Test 123.

Can anyone help me figure out what's going on here?

Thank you so much in advance,

-- Chris


By default DotLiquid uses Ruby's naming convention for methods and properties. In your example ToGive is "renamed" as to_give. If you prefer you can instead use C# naming convention by setting the static propery DotLiquid.Template.NamingConvention = new DotLiquid.NamingConventions.CSharpNamingConvention();

HTH

0

精彩评论

暂无评论...
验证码 换一张
取 消