.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");
}
}
相关推荐
-
Javascript面向对象扩展库代码分享
lang.js库提供了包和类的定义.类的继承与混合(mixin).函数重载等功能,基本可满足大多数面向对象设计的需求.同时支持基于链式的定义方式,让库在使用时更加规范和便捷.下面首先通过简单的例子演示了lang.js的基本功能,之后给出了lang.js的源码及注释. 一.功能介绍 "lang"作为框架的全局定义,其中包括了四个方法: lang.Package(string name) //用于定义包(默认会暴露到全局) lang.Class(string name[, object c
-
收集的一些Array及String原型对象的扩展实现代码
从无忧脚本收集过来的,有些的确还不错,比较实用,值得收藏一下. 扩展Array的原型对象的方法 复制代码 代码如下: // 删除数组中数据 Array.prototype.del = function(n) { if (n<0) return this; return this.slice(0,n).concat(this.slice(n+1,this.length)); } // 数组洗牌 Array.prototype.random = function() { var nr=[], me=
-
一个perl扩展正则表达式代码分析
复制代码 代码如下: my $ip = "192.168.0.1|192.168.0.2|192.168.0.1";if ( $ip =~ / ^ (?: ((?:\d{1,3}\.){3}\d{1,3}) (?= (?: \|(?!\1)(?1) )* \z ) \| )* (?1) $ /x )
-
Javascript string 扩展库代码
Javascript原生的String处理函数显得很不够丰富,原生string函数:http://www.jb51.net/w3school/js/jsref_obj_string.htm问题1:是否有只是针对String类型的扩展库呢?有,不多,不全面. 观点2: JQuery的强大在于DOM操作,因此不希望js string 扩展库是基于jquery开发的,是否认同? 问题3:我们需要什么样的string扩展函数?这个问题可以参考其他js库,以及其他语言的string操作函数 Prototy
-
JavaScript Array扩展实现代码
indexOf 返回元素在数组的索引,没有则返回-1.与string的indexOf方法差不多. 如果其他浏览器没有实现此方法,可以用以下代码实现兼容: 复制代码 代码如下: Array.prototype.indexOf = function(el, start) { var start = start || 0; for ( var i=0; i < this.length; ++i ) { if ( this[i] === el ) {
-
本地对象Array的原型扩展实现代码
复制代码 代码如下: Array.prototype.del=function(){ var b={},c,i=0,l=this.length,j; for(;i<l;i++){ c=this.shift(); c in b ? b[c]++ : b[c]=0; } for(j in b){ if(b[j]>0)this.push(+j||j); } return this; } var a=[1,2,2,3,3,3,'a','b','b']; alert(a.del()); 果果的去重方法
-
.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 com
-
javascript数组的扩展实现代码集合
Array.prototype.del = function(n) { if (n<0) return this; return this.slice(0,n).concat(this.slice(n+1,this.length)); } // 数组洗牌 Array.prototype.random = function() { var nr=[], me=this, t; while(me.length>0) { nr[nr.lengt
-
JS的数组的扩展实例代码
Array.prototype.del = function(n) { if (n<0) return this; return this.slice(0,n).concat(this.slice(n+1,this.length)); } // 数组洗牌 Array.prototype.random = function() { var nr=[], me=this, t; while(me.length>0) { nr[nr.length] = me[t = Math.floor(Math.
-
基于jQuery的一个扩展form序列化到json对象
复制代码 代码如下: $.fn.serializeObject = function() { var o = {}; var a = this.serializeArray(); $.each(a, function() { if (o[this.name]) { if (!o[this.name].push) { o[this.name] = [ o[this.name] ]; } o[this.name].push(this.value || ''); } else { o[this.nam
随机推荐
- Swift 3.0 enum 的灵活使用介绍
- 详解vue 模版组件的三种用法
- 举例说明Lua中元表和元方法的使用
- 作为程序员必知的16个最佳PHP库
- PHP中::、->、self、$this几种操作符的区别介绍
- PHP获取youku视频真实flv文件地址的方法
- C#设计模式之Strategy策略模式解决007大破密码危机问题示例
- Android仿新浪微博启动界面或登陆界面(1)
- ActiveX控件与Javascript之间的交互示例
- PHP批量修改文件名称的方法分析
- Linux日志式文件系统面面观
- 详解MySQL性能优化(二)
- 兼容IE/Firefox/Opera/Safari的检测页面装载完毕的脚本Ext.onReady的实现
- 一道关于JavaScript变量作用域的面试题
- linux修改mac地址方法分享
- C# winfrom 模拟ftp文件管理实现代码
- 详解C 语言项目中.h文件和.c文件的关系
- Go语言中切片使用的注意事项小结
- 解决node修改后需频繁手动重启的问题
- Java微信公众平台之自定义菜单
