public static void CopyPropertyValuesFrom <T>(this Object obj, T source, AccessorNameTransform nameTransform = null, AccessorFilter filter = null) { var properties = filter != null? filter(source.GetType().GetProperties()) : source.GetType().GetProperties(); foreach (var getter in properties) { if (nameTransform != null) { obj.SetValue(nameTransform(getter), ((PropertyInfo)getter).GetValue(source, null)); } else { obj.SetValue(getter.Name, ((PropertyInfo)getter).GetValue(source, null)); } } }
public static void CopyFieldValuesFrom <T>(this Object obj, T source, AccessorNameTransform nameTransform = null, AccessorFilter filter = null) { var fields = filter != null? filter(source.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) : source.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); foreach (var getter in fields) { if (nameTransform != null) { obj.SetValue(nameTransform(getter), ((FieldInfo)getter).GetValue(source)); } else { obj.SetValue(getter.Name, ((FieldInfo)getter).GetValue(source)); } } }
public static void CopyValuesFrom <T>(this Object obj, T source, AccessorNameTransform nameTransform = null, AccessorFilter filter = null) { CopyFieldValuesFrom(obj, source, nameTransform, filter); CopyPropertyValuesFrom(obj, source, nameTransform, filter); }
public static void CopyValuesTo <T>(this Object source, T target, AccessorNameTransform nameTransform = null, AccessorFilter filter = null) { target.CopyValuesFrom(source, nameTransform, filter); }