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类的扩展途径,书写和规则也简单的要命. 编写扩展方法有下面几个要求: 第一:扩展方法所在 ...
随机推荐
- 完美解决在Servlet中出现一个输出中文乱码的问题
@Override public void doPost(HttpServletRequest reqeust, HttpServletResponse response) throws Servle ...
- 【Codeforces 977F】Consecutive Subsequence
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 设f[i]表示i作为序列的最后一个数字,最长的连续序列的长度. 用f[i]和f[i-1]+1来转移即可 [代码] import java.io ...
- HDU 4923 (贪心+证明)
Room and Moor Problem Description PM Room defines a sequence A = {A1, A2,..., AN}, each of which is ...
- hihoCoder #27
A QvQ B 题目:http://hihocoder.com/problemset/problem/1470 分析:dfs序+栈+数学 可以发现,对于每组询问,树上是有很多点都只能等于0的 对于每个 ...
- apache2 ubuntu18.04 配置虚拟端口
修改3个文件/etc/apache2/apache2.conf/etc/apache2/ports.conf/etc/apache2/sites-available/000-default.conf ...
- ci get_instance()
你随便下个CI框架的源码都会看到很多的get_instance() 函数,这个函数是用来获取CI 的全局超级对象,CI 是单例模式的框架,所有全局有一个超级对象.因为只有一个实例,所以无论这个函数使用 ...
- HDU 2489 Minimal Ratio Tree (dfs+Prim最小生成树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2489 Problem Description For a tree, which nodes and ...
- POJ2481:Cows(树状数组)
Description Farmer John's cows have discovered that the clover growing along the ridge of the hill ( ...
- CSDN学院 免费技术答疑公开课,本周六场即将开播~~~
为了酬谢广大学员.CSDN学院特推出免费技术答疑公开课.让您开启一段充实的学习之旅~ 本周六场即将开播. ----------------------------------------------- ...
- Cocos Code IDE + Lua初次使用FastTiledMap的坑
近期想玩玩Lua.又想玩玩Cocos Code IDE.更加想写一个即时战斗的.防守的.会动的.有迷雾的.要探索的(旁白:给我停!)跑地图游戏. 于是我就用Cocos Code IDE来写游戏了.挑战 ...