C # DotLiquid Simple Example Unit Test does not work as expected

I wanted to use the excellent DotLiquid and tried to give the following example (written by me) without any major success.

internal class AuthorDrop : Drop {
    private String lname;

    public String ToGive { get { return lname; } }


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

with appropriate 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 leads to the conclusion

hi

instead of hi Test 123.

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

Thank you so much in advance

- Chris

+3
source share
1 answer

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

NTN

+10
source

Source: https://habr.com/ru/post/1784247/


All Articles