标签:nbsp ogr rgs 分享图片 技术 value image val bsp
namespace EF6._0Test { class Program { /// <summary> /// PropertyInfo的简单使用 /// </summary> static void Main(string[] args) { Student stu1 = new Student() { id = 1, name = "张三", length = 175, datetime = DateTime.Now }; Student1 stu2 = new Student1() { id = 2, name = "李四", length = 176, datetime = DateTime.Now.AddDays(1) }; var list1 = stu1.GetType().GetProperties(); var list2 = stu2.GetType().GetProperties(); //stu1 mapping stu2 foreach (var item in list1) { var entityPi = list2.FirstOrDefault(p => p.Name == item.Name); entityPi.SetValue(stu2, item.GetValue(stu1)); } Console.WriteLine($"id={stu2.id} ,name={stu2.name} ,length={stu2.length} ,datetime={stu2.datetime}"); Console.ReadLine(); } } public class Student { public int id { get; set; } public string name { get; set; } public decimal length { get; set; } public DateTime datetime { get; set; } } public class Student1 { public int id { get; set; } public string name { get; set; } public decimal length { get; set; } public DateTime datetime { get; set; } } }
标签:nbsp ogr rgs 分享图片 技术 value image val bsp
原文地址:http://www.cnblogs.com/lgxlsm/p/7879588.html