class InvalidOperationException<T> : InvalidOperationException where T : Command { public InvalidOperationException(string message) : base(message " /> 国产主播喷水一区二区,色偷偷久久一区二区三区,国产美女一区

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

.NET 擴展實現代碼

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技術.NET 擴展實現代碼,轉載需保留來源!

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

主站蜘蛛池模板: 保靖县| 宜兰县| 施秉县| 上高县| 灵璧县| 松溪县| 洪雅县| 蕉岭县| 兴城市| 林甸县| 固镇县| 大邑县| 重庆市| 勃利县| 道孚县| 呼伦贝尔市| 子长县| 农安县| 河源市| 高州市| 苍梧县| 阿克| 山东省| 和田市| 乌兰浩特市| 泸西县| 阿城市| 高碑店市| 赣州市| 竹山县| 南川市| 富锦市| 北辰区| 隆安县| 平乡县| 夏津县| 当雄县| 新竹县| 阳城县| 青浦区| 扬州市|