public static string SortParam<T>(T t)
{
string tStr = string.Empty;
if (t == null)
{
return string.Empty;
}
System.Reflection.PropertyInfo[] properties = t.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
if (properties.Length <= 0)
{
return string.Empty;
}
foreach (System.Reflection.PropertyInfo item in properties.OrderBy(m => m.Name))//排序后组成字符串
{
string name = item.Name;//字段名称
object value = item.GetValue(t, null);//值
if (item.PropertyType.IsValueType || item.PropertyType.Name.StartsWith("String"))
{
if (value != null)
tStr += (string.Format("{0}{1}", name, value));
}
else
{
SortParam(value);//集合字段递归
}
}
//tStr = tStr.OrderBy(m => m).ToList();
return tStr;
}

 

public IList<T> GetData(SqlDataReader reader)
{
IList<T> list = new List<T>();
Type type = typeof(T);
PropertyInfo[] properties = type.GetProperties(); while (reader.Read())
{
T t = Activator.CreateInstance<T>();
for (int i = 0; i < properties.Length; i++)
{
properties[i].SetValue(t, reader[i + 1], null); } list.Add(t);
} return list;
}

最新文章

  1. codevs 1036 商务旅行(Targin求LCA)
  2. [hdu 3376]Matrix Again
  3. redis 初探
  4. Octopus系列之接下来的任务
  5. MySql文章
  6. (Android学习系列)三,窗口的常用事件
  7. 13. Roman to Integer
  8. COCOS2D-JS入门-官网template源码解析
  9. canvas的beginPath和closePath分析总结,包括多段弧的情况
  10. 【单调栈】最长不上升子序列变式,洛谷 P2757 导弹的召唤
  11. 使用定时器限制点击按钮发送短信(附源码)--JavaScript小案例
  12. 网络安全实验室_注入关writeup
  13. 开源一个自己造的轮子:基于图的任务流引擎GraphScheduleEngine
  14. Rails报找不到sanitize和raw方法的解决
  15. Swagger UI及 Swagger editor教程 API文档搭配 Node使用
  16. PBRT笔记(6)——采样和重构
  17. java 保证程序安全退出
  18. $Django patch与put,视图组件,路由控制,响应器
  19. 虚拟机安装Linux Centos
  20. 安卓ADB命令

热门文章

  1. Error creating bean with name &#39;entityManagerFactory&#39; defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method fail
  2. [cogs736][网络流24题#13]星际转移[网络流,网络判定]
  3. 【ACM】hdu_1276_士兵队列训练问题_201308131032
  4. Spring MVC-集成(Integration)-生成Excel示例(转载实践)
  5. Java对二叉搜索树进行插入、查找、遍历、最大值和最小值的操作
  6. samba笔记
  7. Recovery 中的UI知识积累【转】
  8. hdu 1075(字典树)
  9. Spark之Structured Streaming
  10. lodop使用