广

ASP.NET

  • IOS开发
  • android开发
  • PHP编程
  • JavaScript
  • ASP.NET
  • ASP编程
  • JSP编程
  • Java编程
  • 易语言
  • Ruby编程
  • Perl编程
  • AJAX
  • 正则表达式
  • C语言
  • 编程开发

    .NET 扩展实现代码

    2018-05-08 11:29:36 次阅读 稿源:互联网
    广告
    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");
    }
    }

    一起学吧部分文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与一起学吧进行文章共享合作。

    广告
    广告
    广告