简体   繁体   English

SmartFormat - 覆盖格式方法

[英]SmartFormat - Override format method

I want to override Format method of SmartFormat.SmartFormatter class. Can anyone give me a sample or any idea on how to do that?我想覆盖 SmartFormat.SmartFormatter class 的 Format 方法。任何人都可以给我一个示例或关于如何做到这一点的任何想法吗?

The SmartFormat SmartFormatter class is not designed to be inherited. SmartFormat SmartFormatter class不是为继承而设计的。 The best alternative is to create an extension method.最好的选择是创建一个扩展方法。 Example:例子:

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

Usage:用法:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM