博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
实体copy
阅读量:6870 次
发布时间:2019-06-26

本文共 1712 字,大约阅读时间需要 5 分钟。

using System;using System.Collections.Generic;using System.Linq;using System.Reflection;using System.Text;namespace U1City.Infrastructure{    public class EntityExtension    {        public static T EntityToEntityByField
(object obj, T newObj) where T : class,new() { if (newObj == null) { newObj = new T(); } PropertyInfo[] propertyInfos = obj.GetType().GetProperties(); PropertyInfo[] newPropertyInfos = typeof(T).GetProperties(); foreach (var newPropertyInfoItem in newPropertyInfos) { foreach (var propertyInfoItem in propertyInfos) { if ( propertyInfoItem.PropertyType.FullName.Equals(newPropertyInfoItem.PropertyType.FullName) && propertyInfoItem.Name == newPropertyInfoItem.Name && propertyInfoItem.CanRead && newPropertyInfoItem.CanWrite ) { newPropertyInfoItem.SetValue(newObj, propertyInfoItem.GetValue(obj, null), null); break; } else if ( propertyInfoItem.Name == newPropertyInfoItem.Name && !propertyInfoItem.PropertyType.FullName.Equals(newPropertyInfoItem.PropertyType.FullName)) { //?? EntityToEntityByField(propertyInfoItem.GetValue(obj, null), newPropertyInfoItem.GetValue(newObj, null)); } } } return newObj; } }}

 

转载于:https://www.cnblogs.com/xmyy/articles/3458180.html

你可能感兴趣的文章
关于APP接口设计
查看>>
【VI】如何再执行上一个(历史)命令(已解决)
查看>>
KendoUI系列:DropDownList
查看>>
Axure7.0汉化方法
查看>>
我的MYSQL学习心得(九)
查看>>
JavaScript高级程序设计学习笔记--DOM
查看>>
Python易学就会(五)turtle绘制椭圆与递归
查看>>
echarts map地图设置外边框或者阴影
查看>>
webpack4学习总结
查看>>
vue.js vue-router history模式路由,域名二级目录子目录nginx配置
查看>>
web前端规范
查看>>
理解网页的关键渲染路径(CRP)
查看>>
使用vue-cli脚手架+webpack搭建vue项目
查看>>
Docker - 03 编排容器 Docker Compose 指令速查表
查看>>
Mybatis基本映射--INSERT
查看>>
移动 web 端屏幕适配 - rem
查看>>
聊聊hystrix的BucketedCounterStream
查看>>
50多种适合机器学习和预测应用的API,你的选择是?(2018年版本)
查看>>
【题目】【4天】寻宝
查看>>
Flutter教程(一) 十分钟了解Flutter
查看>>