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

推荐订阅源

N
News and Events Feed by Topic
D
DataBreaches.Net
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recorded Future
Recorded Future
Y
Y Combinator Blog
C
Check Point Blog
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence
小众软件
小众软件
F
Full Disclosure
S
SegmentFault 最新的问题
Blog — PlanetScale
Blog — PlanetScale
B
Blog RSS Feed
Martin Fowler
Martin Fowler
P
Proofpoint News Feed
博客园 - 司徒正美
量子位
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss
T
Tenable Blog
P
Privacy International News Feed
T
The Exploit Database - CXSecurity.com
C
Cyber Attacks, Cyber Crime and Cyber Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
G
Google Developers Blog
P
Proofpoint News Feed
T
Threatpost
Know Your Adversary
Know Your Adversary
aimingoo的专栏
aimingoo的专栏
Latest news
Latest news
Security Latest
Security Latest
Cyberwarzone
Cyberwarzone
A
About on SuperTechFans
P
Palo Alto Networks Blog
Stack Overflow Blog
Stack Overflow Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Hacker News
The Hacker News
A
Arctic Wolf
AWS News Blog
AWS News Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
NISL@THU
NISL@THU
Last Week in AI
Last Week in AI
Hacker News - Newest:
Hacker News - Newest: "LLM"
Spread Privacy
Spread Privacy
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Application and Cybersecurity Blog
Application and Cybersecurity Blog
I
InfoQ
J
Java Code Geeks
H
Help Net Security

博客园 - Tonyyang

【XAF】如何通过前缀或自定义架构将数据库表与内置系统表分开 Power Shell 7 和5.1 批量给pdf添加页码 [XAF] Declare Conditional Appearance Rules in Code DataTableHelper C# 多任务数据同步 【原】 XAF Localization改用百度翻译 C#百度翻译--亲测试可用 SqlQueryDynamic BOM导入 C#上传到FTP Server FREE OFFER - .NET App Security API (Role-based Access Control) 后台管理框架 JSON序列化和反序列化日期时间的处理 Asp.net MVC 上传文件 Asp.net MVC bootstrap 穿梭框 EXT.NET Combox下拉Grid 转 Refresh Excel Pivot Tables Automatically Using SSIS Script Task SQL Server Integration Services SSIS最佳实践 PowerBI
Model to Model
Tonyyang · 2021-08-26 · via 博客园 - Tonyyang

C#

  /// <summary>
        /// Model to Model
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="Tn">新的类</typeparam>
        /// <param name="objmodel">T类的参数值</param>
        /// <param name="nobjModel">Tn类一个空的实例化</param>
        /// <returns></returns>
        public static Tn ModelToModel<T, Tn>(T objmodel, Tn nobjModel)
        {
            Tn Nobjmodel = nobjModel;
            //被继承的类
            Type modelType = typeof(T);
            Type newModel = typeof(Tn);//继承后的新类
            PropertyInfo[] newpropertys = modelType.GetProperties();//列举出新的类中信息
            //循环新类的属性
            foreach (PropertyInfo pi in newpropertys)
            {
                string ParaName = pi.Name;//参数名称
                string ParamType = pi.PropertyType.Name;//字段类型 int/DateTime/string 等等
                object vaule = modelType.GetProperty(ParaName).GetValue(objmodel, null);//从被继承的类中根据相同字段名称读取类的值
                if (vaule != null) {
                    var property = newModel.GetProperty(ParaName);
                    if(property!=null)
                        property.SetValue(Nobjmodel, vaule, null);//给新版本的类参数赋值
                }
            }
            return Nobjmodel;
        }