Created
June 7, 2014 15:29
-
-
Save odytrice/d96a7fb822dad9aad159 to your computer and use it in GitHub Desktop.
Simple Auto Mapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Extensions{ | |
public void Assign(this object destination, object source) | |
{ | |
if (source != null) | |
{ | |
var destProperties = destination.GetType().GetProperties(); | |
foreach (var sourceProperty in source.GetType().GetProperties()) | |
{ | |
foreach (var destProperty in destProperties) | |
{ | |
if (destProperty.Name == sourceProperty.Name && destProperty.PropertyType.IsAssignableFrom(sourceProperty.PropertyType)) | |
{ | |
destProperty.SetValue(this, sourceProperty.GetValue(source, new object[] { }), new object[] { }); | |
break; | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment