另一种选择,是创造所有ViewPages的基类。隐藏现有的HtmlHelper财产与自己的版本:
public class MyHtmlHelper : HtmlHelper
{
// Take helper service, implement special methods
}
public class MyViewPage : ViewPage
{
protected new MyHtmlHelper HtmlHelper { get; set; }
// Wire up HtmlHelper as appropriate -- which is not going to be easy since
// the base property could be set at any time.
}
现在所有视图页面会使用您的特殊MyHtmlHelper所有您特制的酱汁,他们甚至都不需要是扩展方法。一种变体是让您的MyHtmlHelper公开该服务并继续编写定位该帮助程序的扩展方法。
适应静态类:
有时某个应用程序将相关功能集成到一类的静态函数:
static class IdGenerator
{
static int _next = 0;
public static int GetNext()
{
return ++_next;
}
}
这种
卫生署,是啊。我修好了它。 – 2009-06-08 15:17:26