惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Last Watchdog
The Last Watchdog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Secure Thoughts
MongoDB | Blog
MongoDB | Blog
博客园 - Franky
T
Tor Project blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Google DeepMind News
Google DeepMind News
L
LINUX DO - 最新话题
博客园_首页
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Vercel News
Vercel News
Last Week in AI
Last Week in AI
月光博客
月光博客
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
博客园 - 叶小钗
NISL@THU
NISL@THU
C
Check Point Blog
K
Kaspersky official blog
N
News and Events Feed by Topic
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
A
Arctic Wolf
T
Threatpost
GbyAI
GbyAI
L
LINUX DO - 热门话题
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy & Cybersecurity Law Blog
N
News and Events Feed by Topic
Scott Helme
Scott Helme
P
Privacy International News Feed
The Register - Security
The Register - Security
G
GRAHAM CLULEY
Recorded Future
Recorded Future
Apple Machine Learning Research
Apple Machine Learning Research
C
Cybersecurity and Infrastructure Security Agency CISA
B
Blog
Project Zero
Project Zero
Cyberwarzone
Cyberwarzone
Webroot Blog
Webroot Blog
Microsoft Security Blog
Microsoft Security Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
D
DataBreaches.Net
J
Java Code Geeks
AWS News Blog
AWS News Blog
Help Net Security
Help Net Security
Engineering at Meta
Engineering at Meta
M
MIT News - Artificial intelligence
T
Threat Research - Cisco Blogs
Google DeepMind News
Google DeepMind News

博客园 - chengeng

让SVN可以修改提交log Python开发环境搭建 ubuntu 安装mysql Android Studio汉化备忘 DataConvert VS2022,IF条件为Flase也进入断点,设置方法 在CentOS上,查看CPU、内存和磁盘的指标命令 mysql 常用语句 MQTT服务器订阅消息例子 Java 异步调用方法 修改Web.config,IIS启动速度提升60倍 Windows smbv1共享协议开启 windows 10 激活 根据json内容更新表的一行,字段数量不固定,但名称需要一致 Windows 服务启动共享目录 FastReport 打印弹框,无法关闭(自己特定的场景,做个备忘,请勿参考) WinForm 指定时间没有操作键盘鼠标,弹出屏幕保护 MDns C# 实现 Makaretu.Dns.Multicast WinForm截屏 C#根据json内容动态生成SQL语句,字段数量可以不一样 金蝶云星空BOS平台官网知识 .Net Framework 离线安装包
c#将一个类型对象数据赋值到另一个类型对象(名字相同的情况)
chengeng · 2024-04-28 · via 博客园 - chengeng
 /// <summary>
 /// 将一个类型对象数据赋值到另一个类型对象(名字相同的情况)
 /// </summary>
 /// <typeparam name="T">目标类型</typeparam>
 /// <param name="entity">目标类型对象</param>
 /// <param name="dto">源对象</param>
 /// <returns></returns>
 public static object EntityDataEntity<T>(T entity, object dto) where T:class,new()
 {
     //if (dto == null || entity == null){return entity;}

     //System.Reflection.PropertyInfo[] entityProperties = entity.GetType().GetProperties(System.Reflection.BindingFlags.Public);
     //System.Reflection.PropertyInfo[] dtoProperties = dto.GetType().GetProperties(System.Reflection.BindingFlags.Public);

     System.Reflection.PropertyInfo[] entityProperties = entity.GetType().GetProperties();
     System.Reflection.PropertyInfo[] dtoProperties = dto.GetType().GetProperties();

     if (entityProperties.Length<=0){return entity;}
     if (dtoProperties.Length <= 0){return entity;}

     foreach (System.Reflection.PropertyInfo item in entityProperties) {
         foreach (var dtoItem in dtoProperties)
         {
             if (item.Name == dtoItem.Name)
             {
                 if (item.PropertyType.IsValueType || item.PropertyType.Name.StartsWith("String"))
                 {
                     object value = dtoItem.GetValue(dto, null);
                     if (value != null)
                         item.SetValue(entity, value, null);
                     break;
                 }
                 else { 
                     object value = item.GetValue(entity, null);
                     object dtoValue=dtoItem.GetValue(dto, null);
                     value = EntityDataEntity(value, dtoValue);
                     if (value != null)
                         item.SetValue(entity, value, null);
                     break;
                 }
             }
         }
     }
     return entity;
 }