.NET 擴(kuò)展實(shí)現(xiàn)代碼
更新時(shí)間:2008年09月14日 08:30:40 作者:
增強(qiáng).net的功能需要用到了擴(kuò)展實(shí)現(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)文章
asp.net 結(jié)合mysql存儲(chǔ)過程進(jìn)行分頁代碼
最近用mysql + asp.net來寫網(wǎng)站,既然mysql已經(jīng)支持存儲(chǔ)過程了,那么像分頁這么常用的東西,當(dāng)然要用存儲(chǔ)過程啦2008-11-11MVC微信網(wǎng)頁授權(quán)獲取用戶OpenId
這篇文章主要為大家詳細(xì)介紹了MVC微信網(wǎng)頁授權(quán),在模板頁中獲取用戶openid,感興趣的小伙伴們可以參考一下2016-09-09.net數(shù)據(jù)庫(kù)操作框架SqlSugar的簡(jiǎn)單入門
這篇文章主要介紹了.net數(shù)據(jù)庫(kù)操作框架SqlSugar的簡(jiǎn)單入門,幫助大家更好的理解和學(xué)習(xí)使用.net技術(shù),感興趣的朋友可以了解下2021-04-04asp.net下判斷用戶什么時(shí)候離開,以什么方式離開
asp.net下判斷用戶什么時(shí)候離開,以什么方式離開...2007-03-03ASP.NET MVC3 SEO優(yōu)化:利用Routing特性提高站點(diǎn)權(quán)重
這篇文章主要介紹了ASP.NET MVC3 SEO優(yōu)化:利用Routing特性消除多個(gè)路徑指向同一個(gè)Action,從而提高站點(diǎn)權(quán)重,需要的朋友可以參考下。2016-06-06.NET讀寫Excel工具Spire.Xls使用入門教程(1)
這篇文章主要為大家詳細(xì)介紹了.NET讀寫Excel工具Spire.Xls使用入門教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-11-11