12345678910111213141516171819202122232425262728293031323334353637 |
- using System;
- using System.Collections.Generic;
- using System.Web;
- using System.Linq;
- using System.Text;
- using System.Reflection;
- namespace CP.Common
- {
- /// <summary>
- /// 实体类转换
- /// </summary>
- public class ToModel
- {
- public static R Mapping<R, T>(T model)
- {
- R result = Activator.CreateInstance<R>();
- foreach (PropertyInfo info in typeof(R).GetProperties())
- {
- PropertyInfo pro = typeof(T).GetProperty(info.Name);
- if (pro != null)
- {
- try
- {
- info.SetValue(result, pro.GetValue(model));
- }
- catch (Exception)
- {
- }
- }
-
- }
- return result;
- }
- }
- }
|