.NET 实体转换辅助类
- /// <summary>
- /// 实体转换辅助类
- /// </summary>
- public class ModelConvertHelper<T> where T : new()
- {
- public static IList<T> ConvertToModelList(DataTable dt)
- {
- // 定义集合
- IList<T> ts = new List<T>();
- // 获得此模型的类型
- Type type = typeof(T);
- string tempName = "";
- foreach (DataRow dr in dt.Rows)
- {
- T t = new T();
- // 获得此模型的公共属性
- PropertyInfo[] propertys = t.GetType().GetProperties();
- foreach (PropertyInfo pi in propertys)
- {
- tempName = pi.Name;
- // 检查DataTable是否包含此列
- if (dt.Columns.Contains(tempName))
- {
- // 判断此属性是否有Setter
- if (!pi.CanWrite) continue;
- object value = dr[tempName];
- if (value != DBNull.Value)
- pi.SetValue(t, value, null);
- }
- }
- ts.Add(t);
- }
- return ts;
- }
.NET 实体转换辅助类的更多相关文章
- DataTable转List<Model>通用类【实体转换辅助类】
/// <summary> /// DataTable转List<Model>通用类[实体转换辅助类] /// </summary> public class Mo ...
- Datatable转实体 实体转换辅助类
using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.R ...
- HBaseConvetorUtil 实体转换工具
HBaseConvetorUtil 实体转换工具类 public class HBaseConvetorUtil { /** * @Title: convetor * @De ...
- html实体转换
摘要: 在 HTML 中,某些字符是预留的.在 HTML 中不能使用小于号(<)和大于号(>),这是因为浏览器会误认为它们是标签.如果希望正确地显示预留字符,我们必须在 HTML 源代码中 ...
- C# 获取config文件 实体转换
随着项目的扩展,单独的key,value配置文件已经不能满足需求了 这里需要自定义配置节点,例如 <!--自定义 具体实体类配置问节点信息--> <School Name=" ...
- C# 实体集合和实体转换成相应的string、XDocument、XElement、XDocument
https://msdn.microsoft.com/zh-cn/library/system.xml.linq.xelement(v=vs.110).aspx XElement.Parse 方法 ( ...
- C#中实体集合和实体转换成相应的string、XDocument、XElement
C#中实体集合和实体转换成相应的string.XDocument.XElement public class SimpleXmlConverter { public static string ToX ...
- .Net Core2.2 使用 AutoMapper进行实体转换
一.遇到的问题 在. Core Api 的编写中,我们经常会对一些功能点进行新增编辑操作,同时我们有时也会进行查询,但是我们查询的表的数据与我们返回的数据相差甚大,这是我们有需要自己手动进行类型的转换 ...
- mapstruct 实体转换及List转换,@Mapper注解转换
本文参考 https://blog.csdn.net/u012373815/article/details/88367456 主要是为了自己使用方便查询. 这些都是我平时用到了,大家有什么好方法或者有 ...
随机推荐
- iptables的启动和关闭【转载】
原文网址:http://os.51cto.com/art/201103/249049.htm iptables的启动和关闭: 1.启动和关闭iptables 下面将正式使用iptables来创建防火墙 ...
- java编程思想第五章初始化与清理
5.1使用构造器确保初始化: 构造器与一般方法一样,但是没有返回值,且其方法名与类名完全相同. 不接受任何参数的构造器成为默认构造器,也叫无参构造器. 5.2 方法重载: 为什么会有方法重载? 构造器 ...
- linux环境下搭建jenkins实现自动部署
写在前面:公司项目初期,环境一切从始.因此,项目的发布环境需要自己搭建.就动手搭建了jenkins,在此把个人的搭建过程以及搭建中碰到的问题一起总结一下. 1. 准备环境. 首先,需要jdk是必须要安 ...
- PCIE编程1:lspci操作
lspci 是一个用来显示系统中所有PCI总线设备或连接到该总线上的所有设备的工具. 列出所有的PCIE设备: lspci 选项: -v 使得 lspci 以冗余模式显示所有设备的详细信息. -vv ...
- LdapContext获取对象的属性
// dn = "cn=1,cn=Users,DC=域名,DC=COM";// Attributes answer = ctx.getA ...
- Annotation之四:注解中的-Xlint:unchecked和 -Xlint:deprecation
一.-Xlint:unchecked用法 对如下Test.java编译时 package com.dxz.annotation; import java.util.ArrayList; import ...
- Oracle RMAN 学习
Oracle RMAN 学习:三思笔记 1 进入rman Rman--物理备份(结构/数据) 1 本地db Cmd set oracle_sid=orcl 1 rman target / Rman&g ...
- linux命令 把Windows 文件拷贝到linux
scp build.zip mesadmin@dpydalapp01.sl.bluecloud.ibm.com:/tmp // 把Windows上的build.zip拷贝到mesadmin@dpy ...
- rails自定义出错页面
一.出错类型 Exception ActionController::UnknownController, ActiveRecord::RecordNotFound ActionController: ...
- angular之增删改查
<!DOCTYPE html> <html lang="en" ng-app="app"> <head> <meta ...