123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- namespace DirectService.Tools
- {
- internal static class ListEx
- {
- /// <summary>
- /// 把列表转换为(*,*,*,*,...)字符串,空列表返回null
- /// </summary>
- public static string getString<T>(List<T> list)
- {
- string listString;
-
- if (list==null||list.Count<=0)
- {
- return null;
- }
- StringBuilder sb = new StringBuilder("(");
- switch (typeof(T).Name)
- {
- case "DateTime":
- case "String":
- foreach (var item in list)
- {
- sb.Append("'" + item + "',");
- }
- break;
- default:
- foreach (var item in list)
- {
- sb.Append(item + ",");
- }
- break;
- }
- listString = sb.ToString().TrimEnd(',')+')';
- return listString;
- }
- public static string GetWhereStr(List<string> whereList, string connector = "AND")
- {
- string connectStr = " " + connector + " ";
- var whereStr = string.Empty;
- for (int i = 0; i < whereList.Count; i++)
- {
- if (i == 0)
- {
- whereStr += "(" + whereList[i] + ")";
- }
- else
- {
- whereStr += connectStr + "(" + whereList[i] + ")";
- }
- }
- return whereStr;
- }
- }
- }
|