private static Dictionary<string, string> SortedToDictionary(SortedDictionary<string, string> dicArrayPre, params string[] paras)
{
Dictionary<string, string> dict = new Dictionary<string, string>();
foreach (KeyValuePair<string, string> temp in dicArrayPre)
if (!paras.Contains(temp.Key) && !string.IsNullOrEmpty(temp.Value))
dict.Add(temp.Key, temp.Value);
return dict;
}
private static string GetParmStr<T>(T model, bool isUrlEncode = false, params string[] paras)
{
var sortedDict = GetResultDictionary<T>(model);
var dict = FilterParams(sortedDict, paras);
return CreateLinkStringUrl(dict, isUrlEncode);
}
private static SortedDictionary<string, string> GetResultDictionary<T>(T model)
{
SortedDictionary<string, string> sortedDictionary = new SortedDictionary<string, string>();
List<string> paramsList = new List<string>();// 把实体类中的属性名称转换成List<string>
var modelDict = model.GetType().GetProperties().ToDictionary(a => a.Name.Substring(0, 1).ToLower() + a.Name.Substring(1));
foreach (var dkey in modelDict)
paramsList.Add(dkey.Key);

foreach (var p in paramsList)
{
System.Reflection.PropertyInfo pi = null;
if (modelDict.TryGetValue(p, out pi))
{
object obj = pi.GetValue(model, null);
if (pi != null && obj != null && !obj.ToString().Equals(""))
sortedDictionary.Add(p, obj.ToString());
}
}
return sortedDictionary;
}
private static Dictionary<string, string> FilterParams(SortedDictionary<string, string> sortedDictionary, params string[] paras)
{
Dictionary<string, string> dict = new Dictionary<string, string>();
foreach (KeyValuePair<string, string> temp in sortedDictionary)
if (!paras.Contains(temp.Key) && !string.IsNullOrEmpty(temp.Value))
dict.Add(temp.Key, temp.Value);
return dict;
}
private static string CreateLinkStringUrl(Dictionary<string, string> dictionary, bool isUrlEncode = false)
{
StringBuilder stringBuilder = new StringBuilder();
if (isUrlEncode)
{
foreach (KeyValuePair<string, string> temp in dictionary)
stringBuilder.Append(temp.Key + "=" + HttpUtility.UrlEncode(temp.Value) + "&");
}
else
{
foreach (KeyValuePair<string, string> temp in dictionary)
stringBuilder.Append(temp.Key + "=" + temp.Value + "&");
}
int nLen = stringBuilder.Length;
stringBuilder.Remove(nLen - 1, 1);
return stringBuilder.ToString();
}

最新文章

  1. python scrapy+Mongodb爬取蜻蜓FM,酷我及懒人听书
  2. zw版【转发&#183;台湾nvp系列Delphi例程】HALCON SetLineStyle1
  3. (27)odoo 中改变菜单动作的默认视图
  4. 关于for,while与do while
  5. VS2005中SetUnhandledExceptionFilter函数应用
  6. 解决eclipse 使用run运行,始终会跳到debug模式!
  7. Demo02_对结构体进行文件读写_张仕传_作业_
  8. hdu 4472 Count(递推即dp)
  9. jQuery慢慢啃之事件(七)
  10. android 广播分类
  11. Hadoop伪分布式模式部署
  12. 【数据库】数据库的锁机制,MySQL中的行级锁,表级锁,页级锁
  13. [Java] 練習用對戰小遊戲
  14. 针对piix4_smbus ****host smbus controller not enabled的解决方法
  15. Smart/400开发上手1:入门
  16. IIS 部署SSL证书
  17. c#之有参和无参构造函数,扩展方法
  18. windows server 2008 远程桌面(授权、普通用户登录)~ .
  19. spoj 694 705 不相同的子串的个数
  20. Web App三年将取代原生App?

热门文章

  1. 分享Mvc3+NInject+EF+LigerUI权限系统
  2. MongoDB的一些用法(转藏)
  3. [每日一题] OCP1z0-047 :2013-07-26 alter table set unused之后各种情况处理
  4. Excel 开发概述
  5. OpenXml操作Word的一些操作总结.
  6. 【deep learning学习笔记】注释yusugomori的RBM代码 --- 头文件
  7. [C++STDlib基础]关于C标准输入输出的操作——C++标准库头文件&lt;cstdio&gt;
  8. 真的了解js生成随机数吗
  9. php钩子程序设计
  10. Java ArrayList、Vector和LinkedList等的差别与用法(转)