/// <summary> /// Assign all assignable properties from source to target. /// </summary> /// <param name="target">Object to set properties.</param> /// <param name="source">Object to assign.</param> public static void Assign(this object target, object source) { if (ReferenceEquals(target, source) || source == null) { return; } Type targetType = target.GetType(); AssignableAttribute classAssignableAttribute = TypeDescriptor.GetAttributes(targetType).OfType <AssignableAttribute>().FirstOrDefault(); if (classAssignableAttribute != null) { classAssignableAttribute.Assign(target, source); } else { foreach (PropertyDescriptor propInfo in TypeDescriptor.GetProperties(target)) { AssignableAttribute assignableAttribute = propInfo.Attributes.OfType <AssignableAttribute>().FirstOrDefault(); if (assignableAttribute == null) { continue; } assignableAttribute.Assign(source, target, propInfo); } } }
/// <summary> /// Assign all assignable properties from source to target. /// </summary> /// <param name="target">Object to set properties.</param> /// <param name="source">Object to assign.</param> internal void Assign(object target, object source) { if (ReferenceEquals(target, source) || source == null) { return; } Type targetType = target.GetType(); foreach (PropertyDescriptor propInfo in TypeDescriptor.GetProperties(target)) { AssignableAttribute assignableAttribute = propInfo.Attributes.OfType <AssignableAttribute>().FirstOrDefault(); if (assignableAttribute == null) { assignableAttribute = this; } assignableAttribute.Assign(source, target, propInfo); } }