瞎搞八搞,另类PageBase
图:
代码:
子类只要组合模块就能形成丰富多样的PageBase:
代码:
public class PageBase<PageLayout, PageSecurity, PageError>
: System.Web.UI.Page
where PageLayout : IPageLayout, new ()
where PageSecurity : IPageSecurity, new()
where PageError : IPageError, new()
{
protected override void OnPreInit(EventArgs e)
{
PerformSecurity();
PerformLayout();
base.OnPreInit(e);
}
protected override void OnError(EventArgs e)
{
PerformPageError();
base.OnError(e);
}
/// <summary>
/// 处理页面错误
/// </summary>
protected void PerformPageError()
{
PageError handler = GetInstance<PageError>();
handler.HandleError(this);
}
/// <summary>
/// 设置MasterPage
/// </summary>
protected void PerformLayout()
{
PageLayout layout = GetInstance<PageLayout>();
this.MasterPageFile = layout.Layout;
}
/// <summary>
/// 设置权限
/// </summary>
protected void PerformSecurity()
{
PageSecurity security = GetInstance<PageSecurity>();
security.ControlSecurity();
}
/// <summary>
/// 获取一个类型的实例
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
protected T GetInstance<T>() where T : new()
{
return new T();
}
}
: System.Web.UI.Page
where PageLayout : IPageLayout, new ()
where PageSecurity : IPageSecurity, new()
where PageError : IPageError, new()
{
protected override void OnPreInit(EventArgs e)
{
PerformSecurity();
PerformLayout();
base.OnPreInit(e);
}
protected override void OnError(EventArgs e)
{
PerformPageError();
base.OnError(e);
}
/// <summary>
/// 处理页面错误
/// </summary>
protected void PerformPageError()
{
PageError handler = GetInstance<PageError>();
handler.HandleError(this);
}
/// <summary>
/// 设置MasterPage
/// </summary>
protected void PerformLayout()
{
PageLayout layout = GetInstance<PageLayout>();
this.MasterPageFile = layout.Layout;
}
/// <summary>
/// 设置权限
/// </summary>
protected void PerformSecurity()
{
PageSecurity security = GetInstance<PageSecurity>();
security.ControlSecurity();
}
/// <summary>
/// 获取一个类型的实例
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
protected T GetInstance<T>() where T : new()
{
return new T();
}
}
子类只要组合模块就能形成丰富多样的PageBase:
public class PageBase : sssss.PageBase<
LayoutProvider,
sssss.PageSecurityLess,
PageErrorHandler>
{
}
LayoutProvider,
sssss.PageSecurityLess,
PageErrorHandler>
{
}