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

推荐订阅源

月光博客
月光博客
MongoDB | Blog
MongoDB | Blog
Apple Machine Learning Research
Apple Machine Learning Research
The GitHub Blog
The GitHub Blog
博客园 - 聂微东
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
大猫的无限游戏
大猫的无限游戏
WordPress大学
WordPress大学
云风的 BLOG
云风的 BLOG
H
Help Net Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
A
About on SuperTechFans
Hugging Face - Blog
Hugging Face - Blog
罗磊的独立博客
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
Martin Fowler
Martin Fowler
博客园 - 司徒正美
Stack Overflow Blog
Stack Overflow Blog
B
Blog
博客园 - Franky
小众软件
小众软件
Recorded Future
Recorded Future
B
Blog RSS Feed
爱范儿
爱范儿
宝玉的分享
宝玉的分享
L
LangChain Blog
博客园 - 【当耐特】
The Register - Security
The Register - Security
P
Proofpoint News Feed
V
Visual Studio Blog
Blog — PlanetScale
Blog — PlanetScale
雷峰网
雷峰网
Last Week in AI
Last Week in AI
Microsoft Azure Blog
Microsoft Azure Blog
GbyAI
GbyAI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
M
MIT News - Artificial intelligence
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
MyScale Blog
MyScale Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
aimingoo的专栏
aimingoo的专栏
D
Docker
酷 壳 – CoolShell
酷 壳 – CoolShell
阮一峰的网络日志
阮一峰的网络日志
有赞技术团队
有赞技术团队
G
Google Developers Blog
S
SegmentFault 最新的问题
Microsoft Security Blog
Microsoft Security Blog

博客园 - 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;
        }