class InvalidOperationException<T> : InvalidOperationException where T : Command { public InvalidOperationException(string message) : base(message " /> 麻豆中文一区二区,午夜激情成人网,国产乱一区二区

色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

.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");
}
}

AspNet技術(shù).NET 擴展實現(xiàn)代碼,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 阿勒泰市| 喀喇| 留坝县| 巨野县| 资阳市| 桐梓县| 阿拉善右旗| 即墨市| 松江区| 隆昌县| 萝北县| 宁都县| 大邑县| 景宁| 高清| 临漳县| 宁德市| 扶余县| 龙游县| 新民市| 噶尔县| 宜丰县| 蒙自县| 桐庐县| 佛坪县| 宝清县| 萍乡市| 巴南区| 措勤县| 彝良县| 斗六市| 白城市| 沁水县| 牡丹江市| 淮滨县| 瑞金市| 乌鲁木齐市| 怀来县| 正蓝旗| 清镇市| 太仆寺旗|