标签: smartformat.net

列表格式错误中的 SmartFormat.NET 嵌套占位符

我正在尝试测试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)

.net c# string-formatting smartformat.net

2
推荐指数
1
解决办法
1210
查看次数

如何使用带有 SmartFormat 反射语法的 C# 扩展方法?

是否可以使以下示例与 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 用作一个简单示例。

c# reflection extension-methods smartformat.net

2
推荐指数
1
解决办法
1324
查看次数