// -------------------------------------------------------------------------------------------------------------------------- private static void CopyComposite <TFrom, TTo>(TFrom from, TTo to, bool allowNulls, DataMember fromMember, DataMember toMember) { object fromVal = fromMember.GetValue(from); object copied = CreateFrom(toMember.DataType, fromVal, allowNulls); toMember.SetValue(to, copied); }
// -------------------------------------------------------------------------------------------------------------------------- private static void CopyListDataEx <TFrom, TTo>(TFrom from, TTo to, DataMember fromMember, DataMember toMember, Type listType1, Type listType2) { IList sourceList = (IList)fromMember.GetValue(from); IList target = (IList)toMember.GetValue(to); if (target == null) { if (toMember.CanWrite) { target = (IList)Activator.CreateInstance(toMember.DataType, null); toMember.SetValue(to, target); } } else { target.Clear(); } if (sourceList != null) { if (ReflectionTools.IsSimpleType(listType1)) { foreach (var item in sourceList) { target.Add(item); } } else { foreach (var item in sourceList) { object nextItem = DTOMapper.CreateCopy(listType1, listType2, item); target.Add(nextItem); } } } else { // We can't directly write to the list (which is how we got here) so we will just clear it out instead. if (target != null) { target.Clear(); } } }