.NET 扩展实现代码
2008-09-14 08:30
1401 查看
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");
}
}
{
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");
}
}
相关文章推荐
- .NET 扩展实现代码
- 合理使用“.NET 扩展方法”来简化代码(例子:空值判断,利用扩展方法实现LINQ操作符ForEach)
- 用.net实现远程获取其他网站页面内容!(核心代码分析)
- .Net 文本框实现内容提示的实例代码(仿Google、Baidu)
- 用.NET代码扩展Fiddler 【译文】
- 多年一直想完善的自由行政审批流程组件【2002年PHP,2008年.NET,2010年完善数据设计、代码实现】
- 多年一直想完善的自由行政审批流程组件【2002年PHP,2008年.NET,2010年完善数据设计、代码实现】
- .NET:可扩展的 “密码强度” 代码示例
- .net从DataGridView复制到Excel.代码实现。解决乱码问题
- 用.net实现远程获取其他网站页面内容!(核心代码分析)
- 生日悖论扩展引申1-c++代码实现及运行实例结果
- 生日悖论扩展引申1-c++代码实现及运行实例结果
- 生日悖论扩展引申2-c++代码实现及运行实例结果
- 生日悖论扩展引申2-c++代码实现及运行实例结果
- js下通过prototype扩展实现indexOf的代码
- .net实现邮件发送代码
- .net客户端导出Excel实现代码及注意事项