在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
using System; using System.Data.Objects.DataClasses; using System.Reflection; static public void AutoMapping<S, T>(S s, T t) { PropertyInfo[] pps = s.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); Type target = t.GetType(); foreach (var pp in pps) { PropertyInfo targetPP = target.GetProperty(pp.Name); object value = pp.GetValue(s, null); if (targetPP != null && value != null) { targetPP.SetValue(t, value, null); } } } static public void CopyEFObject<S, T>(S s, T t) { PropertyInfo[] pps = s.GetType().GetProperties(); Type target = t.GetType(); foreach (var pp in pps) { PropertyInfo targetPP = target.GetProperty(pp.Name); if (targetPP.IsDefined(typeof(EdmScalarPropertyAttribute))) { object value = pp.GetValue(s, null); if (targetPP != null && value != null) { targetPP.SetValue(t, value, null); } } } } CopyEFObject<Info, Info>(creditInfo, copyCredit); // 反射循环给实体赋值 var list = new List<Abnormal>(); sourceList.ForEach(row => { var entity = new Abnormal(); AutoMapping(row, entity); list.Add(entity); });
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论