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类的扩展途径,书写和规则也简单的要命. 编写扩展方法有下面几个要求: 第一:扩展方法所在 ...
随机推荐
- 工作用linux命令汇总
mv [filepath] [filepath] 移动,前者位置移动到后面位置,也可以用来重命名(mv test.txt newname.txt) cp [filepath] [filepath] 复 ...
- uestc 1903
#include<stdio.h> int main() { int n,m,i,t; scanf("%d",&t); while(t--){ scanf(&q ...
- (13)Corner Detection角点检测
import cv2 import numpy as np img=cv2.imread('opencv-corner-detection-sample.jpg') gray = cv2.cvtCol ...
- JAVA学习课本内容总结
二.基本类型 数组 枚举 1.基本类型 逻辑类型 boolean (true/false) 整数类型 byte(8位) short(16) int(32) long(64) 浮点类型 float ...
- code wars quiz: toInteger
Your task is to program a function which converts any input to an integer. Do not perform rounding, ...
- ubuntu18.04安装magento2
magento2更新很快,使用的技术都是很前沿的,国内外的技术帖子又很少,安装的时候难免会遇到各种各样的问题.我们单位因为是外资,总部在国外,最近在自主开发电商网站,开发语言是php,首选了magen ...
- 连载:面向对象葵花宝典:思想、技巧与实践(34) - DIP原则
DIP,dependency inversion principle,中文翻译为"依赖倒置原则". DIP是大名鼎鼎的Martin大师提出来的.他在1996 5月的C++ Repo ...
- 【bzoj3105】【cqoi2013】【新Nim游戏】【线性基+贪心】
Description 传统的Nim游戏是这种:有一些火柴堆,每堆都有若干根火柴(不同堆的火柴数量能够不同).两个游戏者轮流操作,每次能够选一个火柴堆拿走若干根火柴.能够仅仅拿一根,也能够拿走整堆火柴 ...
- python-paramiko初体验
什么pexpect.pxshll在paramiko面前都是浮云,重要的是paramiko支持windows. 小试牛刀 import paramiko paramiko.util.log_to_fil ...
- mybatis Generator生成代码及使用方式(转载)
转载自:http://www.cnblogs.com/fengzheng/p/5889312.html 文章很棒,很不错,转了.