Python语言技术文档

微信小程序技术文档

php语言技术文档

jsp语言技术文档

asp语言技术文档

C#/.NET语言技术文档

html5/css技术文档

javascript

点击排行

您现在的位置:首页 > 技术文档 > C#/.NET技巧

ASP.NET 扩展实现代码

来源:中文源码网    浏览:128 次    日期:2024-05-03 15:35:40
【下载文档:  ASP.NET 扩展实现代码.txt 】


.NET 扩展实现代码
class Command { public virtual void Execute() { } } class InvalidOperationException : 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( this TCommand command, string message) where TCommand : Command { throw new InvalidOperationException(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"); } }

相关内容