.NET 擴展實現(xiàn)代碼
更新時間:2008年09月14日 08:30:40 作者:
增強.net的功能需要用到了擴展實現(xiàn)代碼,大家可以參考下
class Command
{
public virtual void Execute() { }
}
class InvalidOperationException<T> : InvalidOperationException
where T : Command
{
public InvalidOperationException(string message) : base(message) { }
// some specific information about
// the command type T that threw this exception
}
static class CommandExtensions
{
public static void ThrowInvalidOperationException<TCommand>(
this TCommand command, string message)
where TCommand : Command
{
throw new InvalidOperationException<TCommand>(message);
}
}
class CopyCommand : Command
{
public override void Execute()
{
// after something went wrong:
this.ThrowInvalidOperationException("Something went wrong");
}
}
class CutCommand : Command
{
public override void Execute()
{
// after something went wrong:
this.ThrowInvalidOperationException("Something else went wrong");
}
}
{
public virtual void Execute() { }
}
class InvalidOperationException<T> : InvalidOperationException
where T : Command
{
public InvalidOperationException(string message) : base(message) { }
// some specific information about
// the command type T that threw this exception
}
static class CommandExtensions
{
public static void ThrowInvalidOperationException<TCommand>(
this TCommand command, string message)
where TCommand : Command
{
throw new InvalidOperationException<TCommand>(message);
}
}
class CopyCommand : Command
{
public override void Execute()
{
// after something went wrong:
this.ThrowInvalidOperationException("Something went wrong");
}
}
class CutCommand : Command
{
public override void Execute()
{
// after something went wrong:
this.ThrowInvalidOperationException("Something else went wrong");
}
}
相關(guān)文章
對GridView的行加顏色并彈出Kindeditor的實現(xiàn)思路
本文主要詳細介紹下對GridView的行加顏色并彈出Kindeditor,感興趣的朋友可以了解下,希望可以幫助到你2013-04-04
ASP.NET中TextBox使用Ajax控件顯示日期不全的問題解決方法
這篇文章介紹了ASP.NET中TextBox使用Ajax控件顯示日期不全的問題解決方法,有需要的朋友可以參考一下2013-10-10
asp.net Repeater取得CheckBox選中的某行某個值的c#寫法
asp.net(c#)利用Repeater取得CheckBox選中行的某個值的代碼2008-08-08
Asp.net后臺把腳本樣式輸出到head標簽中節(jié)省代碼冗余
最近在學習開發(fā)服務(wù)器控件,其它就少不了為控件注冊js和css之類的資源文件,或者直接注冊純腳本樣式。其中就遇到如下問題 1、 注冊的資源文件或純腳本樣式在生成的頁面中都不在head標簽中(當然這個不影響頁面功能) 2、 一個頁面使用多個一樣的控件時,會出現(xiàn)重復輸入(出現(xiàn)多余代碼)2013-02-02
ASP.NET檢測到不安全 Request.Form 值解決方案匯總
這篇文章主要介紹了ASP.NET檢測到不安全 Request.Form 值解決方案匯總 ,十分的全面,需要的朋友可以參考下2015-06-06
Linux(Ubuntu)下搭建ASP.NET Core環(huán)境
本文給大家介紹的是無需安裝mono,在Linux(Ubuntu14.04.4 LTS)下搭建ASP.NET Core環(huán)境 繼續(xù).NET跨平臺,希望對大家能夠有所幫助。2016-07-07
Asp.net core中實現(xiàn)自動更新的Option的方法示例
這篇文章主要介紹了Asp.net core中實現(xiàn)自動更新的Option的方法示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-03-03

