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

推荐订阅源

L
LINUX DO - 最新话题
NISL@THU
NISL@THU
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
Schneier on Security
Schneier on Security
宝玉的分享
宝玉的分享
Cisco Talos Blog
Cisco Talos Blog
Help Net Security
Help Net Security
月光博客
月光博客
V
V2EX
量子位
T
Threat Research - Cisco Blogs
A
About on SuperTechFans
Google DeepMind News
Google DeepMind News
Google DeepMind News
Google DeepMind News
P
Privacy International News Feed
S
Secure Thoughts
T
The Exploit Database - CXSecurity.com
P
Proofpoint News Feed
C
CXSECURITY Database RSS Feed - CXSecurity.com
Engineering at Meta
Engineering at Meta
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
A
Arctic Wolf
S
Schneier on Security
H
Hacker News: Front Page
P
Proofpoint News Feed
MyScale Blog
MyScale Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Cisco Blogs
G
GRAHAM CLULEY
The Cloudflare Blog
博客园 - Franky
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
云风的 BLOG
云风的 BLOG
H
Heimdal Security Blog
The GitHub Blog
The GitHub Blog
C
Check Point Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
The Blog of Author Tim Ferriss
小众软件
小众软件
Hacker News: Ask HN
Hacker News: Ask HN
T
Tenable Blog
The Last Watchdog
The Last Watchdog
J
Java Code Geeks
T
Troy Hunt's Blog
B
Blog
Blog — PlanetScale
Blog — PlanetScale
腾讯CDC

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