public static T Transformation(U u) { if (u == null) { return(null); } PropertyInfo[] TProperties = TType.GetProperties(); PropertyInfo[] UProperties = UType.GetProperties(); T t = new T(); foreach (PropertyInfo TProperty in TProperties) { PropertyInfo UProperty = UProperties.FirstOrDefault(x => x.Name == TProperty.Name && x.PropertyType == TProperty.PropertyType); if (UProperty != null) { TProperty.SetValue(t, UProperty.GetValue(u)); } } return(t); }
public static T MergeProperties(T t, U u) { PropertyInfo[] TProperties = TType.GetProperties(); PropertyInfo[] UProperties = UType.GetProperties(); foreach (PropertyInfo TProperty in TProperties) { PropertyInfo UProperty = UProperties.FirstOrDefault(x => x.Name == TProperty.Name && x.GetType() == TProperty.GetType()); if (UProperty != null) { TProperty.SetValue(t, UProperty.GetValue(u)); } } return(t); }