SmartFormat -覆盖格式方法



我想重写SmartFormat的Format方法。SmartFormatter类。谁能给我一个样品或任何关于如何做的想法?

SmartFormat SmartFormatter类不是被设计为继承的。最好的替代方法是创建一个扩展方法。例子:

public static class MySmartExtensions
{
public static string CreateComment(this SmartFormatter sf, string comment, string submittedBy)
{
return sf.Format("Comment from {0}: {1}", submittedBy, comment);
}
}

用法:

Smart.Default.CreateComment("The comment", "joe@example.com");

最新更新