C# DotLiquid 简单示例单元测试未按预期工作
我一直想使用伟大的 DotLiquid 并尝试遵循示例(由我自己编写),但没有取得任何重大成功。
internal class AuthorDrop : Drop {
private String lname;
public String ToGive { get { return lname; } }
public AuthorDrop(String t) {
lname = t;
}
}
与相应的测试
[Test]
public void TestFirstStep() {
Template tpl = Template.Parse("hi {{ author2.togive }}");
Console.WriteLine(tpl.Render(Hash.FromAnonymousObject(new { author2 = new AuthorDrop("Test 123") })));
}
但是,这会导致输出
嗨
而不是 hi 测试 123。
谁能帮我弄清楚这里发生了什么?
预先非常感谢您,
-- 克里斯
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,DotLiquid 使用 Ruby 的方法和属性命名约定。在您的示例中,ToGive 被“重命名”为 to_give。
如果您愿意,可以通过设置静态属性
DotLiquid.Template.NamingConvention = new DotLiquid.NamingConventions.CSharpNamingConvention();
HTH来使用 C# 命名约定
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