我正在尝试测试SmartFormat.NET的功能,但在尝试格式化视图模型项列表时遇到问题。根据这个交流,我想要完成的事情应该可以通过嵌套占位符来实现。
这是我正在使用的模板:
var smartTemplate = @"
<div>This is the title</div>
<div>model name: {Name}</div>
<div>model description: {Description}</div>
<div>model rating: {Rating}</div>
{ItemList:
<div>{NestedName} has number equal to {Number}</div>
}";
Run Code Online (Sandbox Code Playgroud)
还有我的视图模型:
public class SimpleTestVM
{
public string Name { get; set; }
public string Description { get; set; }
public int Rating { get; set; }
public NestedSimpleVM[] ItemList { get; set; }
}
public class NestedSimpleVM
{
public string NestedName { get; set; }
public int …Run Code Online (Sandbox Code Playgroud) 是否可以使以下示例与 SmartFormat.NET 一起使用?
void Main()
{
Dictionary<string,string> ps = new Dictionary<string, string>();
ps["Name"] = "Niels";
Smart.Format("{Name.Foo} is my name", ps).Dump();
}
public static class Extensions
{
public static string Foo(this string bar)
{
return bar.ToUpper();
}
}
Run Code Online (Sandbox Code Playgroud)
这将在 LinqPad 中返回“是我的名字”。我希望它返回“NIELS 是我的名字”。我仅将 ToUpper 用作一个简单示例。