.NET 扩展实现代码
更新时间:2008年09月14日 08:30:40 作者:
增强.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");
}
}
{
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 MVC3 SEO优化:利用Routing特性提高站点权重
这篇文章主要介绍了ASP.NET MVC3 SEO优化:利用Routing特性消除多个路径指向同一个Action,从而提高站点权重,需要的朋友可以参考下。2016-06-06.NET读写Excel工具Spire.Xls使用入门教程(1)
这篇文章主要为大家详细介绍了.NET读写Excel工具Spire.Xls使用入门教程,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-11-11
最新评论