using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils { public class MapperUtil { public static T MapFor(S sourceObj) { if (sourceObj == null) return default(T); var destObj = Activator.CreateInstance(); var sourceType = sourceObj.GetType(); var destType = typeof(T); foreach (var prop in destType.GetProperties()) { var sourceProp = sourceType.GetProperty(prop.Name); if (sourceProp != null && prop.CanWrite) { var value = sourceProp.GetValue(sourceObj); prop.SetValue(destObj, value); } } return destObj; } } }