源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

.NET 扩展实现代码

  • 时间:2020-12-16 09:27 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:.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"); } }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部