Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Extension Method of the Entity Object This copies the values in another EntityObject with common properties
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="source"></param>
- /// <param name="dest"></param>
- public static void MigrateTo<T>(this T source, EntityObject dest) where T : EntityObject
- {
- List<PropertyInfo> sourcePropList = (from a in source.GetType().GetProperties()
- where !a.PropertyType.Namespace.Contains("System.Data")
- select a).ToList();
- List<PropertyInfo> destPropList = (from a in dest.GetType().GetProperties()
- where !a.PropertyType.Namespace.Contains("System.Data")
- select a).ToList();
- foreach (PropertyInfo source_prop in sourcePropList)
- {
- // exclude property named "id" (usually the id of the record)
- if (!source_prop.Name.Equals("id"))
- {
- if (source_prop.GetValue(source, null) != null)
- {
- foreach (PropertyInfo dest_prop in destPropList)
- {
- if (dest_prop.Name.Equals(source_prop.Name))
- {
- dest_prop.SetValue(dest, source_prop.GetValue(source, null), null);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement