123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- namespace Ant.ORM.Tool
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public class ModelCopyModel
- {
- #region 单个实体转换过程
-
-
-
-
- public static M InputToOutput<T, M>(T ObjT)
- where T : new()
- where M : new()
-
- {
- string tempName = string.Empty;
-
-
- M Result = new M();
- PropertyInfo[] propertys = Result.GetType().GetProperties();
-
- foreach (PropertyInfo pr in propertys)
- {
- tempName = pr.Name;
- PropertyInfo findPro = ObjT.GetType().GetProperty(tempName);
- if (findPro != null)
- {
- if (!pr.CanWrite) continue;
-
- object value = findPro.GetValue(ObjT, null);
-
- if (value != DBNull.Value)
- pr.SetValue(Result, value, null);
- }
- }
- return Result;
- }
- #endregion
- #region 两个集合转换过程
-
-
-
-
-
-
-
- public static List<M> ListInputToOutput<T, M>(List<T> objTlist)
- where T : new()
- where M : new()
- {
-
- List<M> ListM = new List<M>();
-
- M TempM = new M();
- foreach (T item in objTlist)
- {
- TempM = InputToOutput<T, M>(item);
- ListM.Add(TempM);
- }
- return ListM;
- }
- #endregion
- }
- }
|