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

推荐订阅源

V
Visual Studio Blog
C
CERT Recently Published Vulnerability Notes
雷峰网
雷峰网
美团技术团队
L
LangChain Blog
Google DeepMind News
Google DeepMind News
博客园 - 【当耐特】
I
InfoQ
www.infosecurity-magazine.com
www.infosecurity-magazine.com
J
Java Code Geeks
B
Blog
博客园 - 三生石上(FineUI控件)
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Secure Thoughts
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园_首页
博客园 - Franky
Apple Machine Learning Research
Apple Machine Learning Research
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
GbyAI
GbyAI
TaoSecurity Blog
TaoSecurity Blog
N
Netflix TechBlog - Medium
H
Heimdal Security Blog
T
Troy Hunt's Blog
N
News and Events Feed by Topic
V2EX - 技术
V2EX - 技术
腾讯CDC
Forbes - Security
Forbes - Security
P
Privacy & Cybersecurity Law Blog
I
Intezer
Hacker News - Newest:
Hacker News - Newest: "LLM"
Y
Y Combinator Blog
The Register - Security
The Register - Security
Martin Fowler
Martin Fowler
Hugging Face - Blog
Hugging Face - Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Blog — PlanetScale
Blog — PlanetScale
L
Lohrmann on Cybersecurity
Security Latest
Security Latest
AWS News Blog
AWS News Blog
Scott Helme
Scott Helme
Webroot Blog
Webroot Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
MongoDB | Blog
MongoDB | Blog
Vercel News
Vercel News
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
S
Security Affairs
P
Privacy International News Feed

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