.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
随机推荐
- java实现微信支付(服务端)
- Java随机生成手机短信验证码的方法
- 9个PHP开发常用功能函数小结
- python计算圆周率pi的方法
- JS下拉框内容左右移动效果的具体实现
- 编程语言Python的发展史
- 两种常用的javascript数组去重方法思路及代码
- 微信小程序 wx:key详细介绍
- c# 泛型类型参数与约束的深入分析
- js的压缩及jquery压缩探讨(提高页面加载性能/保护劳动成果)
- 北京奥运官方网站幻灯切换效果flash版打包下载
- Jquery创建一个层当鼠标移动到层上面不消失效果
- 深入了解JavaScript中的Symbol的使用方法
- 简单的JS控制button颜色随点击更改的实现方法
- 详解nginx反向代理配置及优化
- Java锁之阻塞锁介绍和代码实例
- 机器学习python实战之手写数字识别
- php+ajax登录跳转登录实现思路
- React如何解决fetch跨域请求时session失效问题
- python requests使用socks5的例子
