当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > .NET 扩展实现代码

ASP.NET
获取字符串数组的最后一段字符
asp.net遍历目录文件夹和子目录所有文件
ASP.NET 中文显示之两种解决方法
asp.net替换和恢复html特殊字符
asp.net简化接收参数值的函数
asp.net验证一个字符串是否符合指定的正则表达式
asp.net求3位不同数字的组合数
C#(.NET)数据访问连接、查询、插入等操作的封装类
在ASP.NET2.0中通过Gmail发送邮件的代码
asp.net下配置数据源时出现: 未将对象引用设置到对象的实例。
asp.net gridview强制换行
asp.net gridview多页时的批量删除
未处理的事件"PageIndexChanging" 之解决方案
gridview调整单元格宽度的方法
aspx如果引用cs中的变量的方法
asp.net导出EXCEL的功能代码
asp.net注册Javascript的方法
Asp.Net 文件操作基类
Asp.Net+XML操作基类(修改,删除,新增,创建)
asp.net 获取指定文件夹下所有子目录及文件(树形)

ASP.NET 中的 .NET 扩展实现代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 54 ::
收藏到网摘: n/a

增强.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");
}
}