Extension Methods(扩展方法)
Extension methods allow an exsting type to be extended with new methods without altering the definition of the original type.
{
public static List<KeyValuePair<string, string>> Listize(this string ss)
{
List<KeyValuePair<string, string>> pList = new List<KeyValuePair<string, string>>();
string[] slist = ss.Split(new char[] { ';' });
foreach (string s in slist)
{
if (string.IsNullOrEmpty(s)) continue;
string[] pair = s.Split(new char[] { ':' });
if (pair.Length != 2) continue;
pList.Add(new KeyValuePair<string, string>(pair[0], pair[1]));
}
return pList;
}
public static string MatchAndReplace(this string src, string pattern, string dst)
{
List<string> mList = new List<string>();
foreach (Match m in Regex.Matches(src, pattern))
{
mList.Add(m.Value);
}
foreach (string s in mList)
{
if (string.IsNullOrEmpty(s)) continue;
src = src.Replace(s, dst);
}
return src;
}
}
foreach (string k in po.CustomObject.Keys)
{
if (string.IsNullOrEmpty(k)) continue;
if (string.Compare(k, "DemoZoneList", true) == 0)
{
whereTail = po.CustomObject[k].Value.Listize().BuildWhereClauseInclusive();
}
else if (string.Compare(k, "NonDemoZoneList", true) == 0)
{
whereTail = po.CustomObject[k].Value.Listize().BuildWhereClauseExclusive();
}
}
if (!string.IsNullOrEmpty(whereTail))
{
sql = sql.MatchAndReplace("1[ ]*=[ ]*1", whereTail);
}

Extension Methods(扩展方法)的更多相关文章
- [C#] Extension Method 扩展方法
当我们引用第三方的DLL.或者Visual Studio自己的库的时候,或许会发现这样的一个情况,如果这个类型有一个XX的方法就好了.这时候我们可以用到扩展方法,是我们的代码更加灵活和高效. 这里我举 ...
- C# Extension Methods(C#类方法扩展)
使用Extension methods 可以在已有的类型(types)中添加方法(Methods),而无需通过增加一种新的类型或修改已有的类型. 比如说,想要给string类型增加一个PrintStr ...
- C# -- 扩展方法的应用(Extension Methods)
当你有下面这样一个需求的时候,扩展方法就会起到作用:在项目中,类A需要添加功能,我们想到的就是在类A中添加公共方法,这个显而易见肯定可以,但是由于某种原因,你不能修改类A本身的代码,但是确实又需要增加 ...
- (转)C# -- 扩展方法的应用(Extension Methods)
本文转载自:http://blog.csdn.net/zxz414644665/article/details/9793205 当你有下面这样一个需求的时候,扩展方法就会起到作用:在项目中,类A需要添 ...
- Extension Methods "点"函数方法 扩展方法
原文发布时间为:2011-03-25 -- 来源于本人的百度文章 [由搬家工具导入] http://msdn.microsoft.com/en-us/library/bb383977.aspx 条件: ...
- C# Note21: 扩展方法(Extension Method)及其应用
前言 今天在开会时提到的一个概念,入职3个多月多注重在项目中使用C#的编程知识,一直没有很认真地过一遍C#的全部语法,当我们新人被问及是否了解Extension Method时,一时之间竟不能很通俗准 ...
- [译文]c#扩展方法(Extension Method In C#)
原文链接: https://www.codeproject.com/Tips/709310/Extension-Method-In-Csharp 介绍 扩展方法是C# 3.0引入的新特性.扩展方法使你 ...
- [0] C# 扩展方法(Extension Method)
有时有这样的情况,有一个类,你不能修改它,但你又想对它扩展(添加一个方法),这个时候就可以用到扩展方法了.请看下面的例子: using System;using System.Collections. ...
- c#编程指南(五) 扩展方法(Extension Method)
C# 3.0就引入的新特性,扩展方法可以很大的增加你代码的优美度,扩展方法提供你扩展.NET Framewoke类的扩展途径,书写和规则也简单的要命. 编写扩展方法有下面几个要求: 第一:扩展方法所在 ...
随机推荐
- 如何创建新用户和授予MySQL中的权限
原创官网http://www.howtoing.com/how-to-create-a-new-user-and-grant-permissions-in-mysql/ 关于MySQL MySQL是一 ...
- 数据库删除数据表重复数据,只留下ID较小的行
删除表中重复数据,留下ID比较小的行 delete from 表 where [重复字段] in (select [重复字段] from 表 group by 字段 having count([字段] ...
- [USACO09JAN]全流Total Flow
题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 < ...
- codevs——1979 第K个数
1979 第K个数 时间限制: 1 s 空间限制: 1000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 给定一个长度为N(0<n<=10 ...
- hello2 source analisis(notes)
该hello2应用程序是一个Web模块,它使用Java Servlet技术来显示问候语和响应.使用文本编辑器查看应用程序文件,也可以使用NetBeans IDE. 此应用程序的源代码位于 _tut-i ...
- 桦仔------分享一下我研究SQLSERVER以来收集的笔记
http://www.cnblogs.com/lyhabc/p/3219117.html
- css3 transform对其他样式影响,(尤其是position:flixed)
1.transform 会为当前元素添加 position : relative 特性: 当 magin 为负值的时候,就会覆盖到前面的 元素, 然而如果给前面元素添加了transform 属性后,前 ...
- Pixhawk---超声波模块加入说明(I2C方式)
1 说明 在Pixhawk的固件中,已经实现了串口和i2c的底层驱动,并不须要自己去写驱动.通过串口的方式加入超声波的缺点是串口不够.不能加入多个超声波模块,此时须要用到i2c的方式去加入了.在P ...
- 数据结构——算法之(027)( 在O(1)时间内删除链表结点)
[申明:本文仅限于自我归纳总结和相互交流,有纰漏还望各位指出. 联系邮箱:Mr_chenping@163.com] 题目:在O(1)时间内删除链表结点.且不知道链表头 题目分析: 1.把要删除节点的下 ...
- starUML 2.5.1 for mac
http://www.macupdate.com/app/mac/55571/staruml/download 一直在windows下使用 star UML,占用资源少,简洁易用. Mac下也能够用了 ...