.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 list用法示例详解
- dedecms中常见问题修改方法总结
- PowerShell连接SQL SERVER数据库进行操作的实现代码
- Vue filters过滤器的使用方法
- Python对两个有序列表进行合并和排序的例子
- C#正则用法两例
- php中使用preg_match_all匹配文章中的图片
- python实现的二叉树算法和kmp算法实例
- MYSQL必知必会读书笔记第六章之过滤数据
- JavaScript之Map和Set_动力节点Java学院整理
- java 请求跨域问题解决方法实例详解
- 基于JSON格式数据的简单jQuery幻灯片插件(jquery-slider)
- js判断当前页面在移动设备还是在PC端中打开
- js动态添加事件并可传参数示例代码
- Android UI 之实现多级树形列表TreeView示例
- java Future 接口使用方法详解
- Python2.x中文乱码问题解决方法
- 浅谈PHP中output_buffering
- C#.net编程创建Access文件和Excel文件的方法详解
- python 动态加载的实现方法
