.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");
}
}
相关文章
对GridView的行加颜色并弹出Kindeditor的实现思路
本文主要详细介绍下对GridView的行加颜色并弹出Kindeditor,感兴趣的朋友可以了解下,希望可以帮助到你2013-04-04
ASP.NET中TextBox使用Ajax控件显示日期不全的问题解决方法
这篇文章介绍了ASP.NET中TextBox使用Ajax控件显示日期不全的问题解决方法,有需要的朋友可以参考一下2013-10-10
asp.net Repeater取得CheckBox选中的某行某个值的c#写法
asp.net(c#)利用Repeater取得CheckBox选中行的某个值的代码2008-08-08
Asp.net后台把脚本样式输出到head标签中节省代码冗余
最近在学习开发服务器控件,其它就少不了为控件注册js和css之类的资源文件,或者直接注册纯脚本样式。其中就遇到如下问题 1、 注册的资源文件或纯脚本样式在生成的页面中都不在head标签中(当然这个不影响页面功能) 2、 一个页面使用多个一样的控件时,会出现重复输入(出现多余代码)2013-02-02
ASP.NET检测到不安全 Request.Form 值解决方案汇总
这篇文章主要介绍了ASP.NET检测到不安全 Request.Form 值解决方案汇总 ,十分的全面,需要的朋友可以参考下2015-06-06
Linux(Ubuntu)下搭建ASP.NET Core环境
本文给大家介绍的是无需安装mono,在Linux(Ubuntu14.04.4 LTS)下搭建ASP.NET Core环境 继续.NET跨平台,希望对大家能够有所帮助。2016-07-07
Asp.net core中实现自动更新的Option的方法示例
这篇文章主要介绍了Asp.net core中实现自动更新的Option的方法示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2019-03-03


最新评论