.NET 扩展实现代码_asp.net教程-查字典教程网
.NET 扩展实现代码
.NET 扩展实现代码
发布时间:2016-12-29 来源:查字典编辑
摘要:classCommand{publicvirtualvoidExecute(){}}classInvalidOperationExcepti...

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

}

}

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新asp.net教程学习
    热门asp.net教程学习
    编程开发子分类