Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@odytrice
Created June 7, 2014 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odytrice/d96a7fb822dad9aad159 to your computer and use it in GitHub Desktop.
Save odytrice/d96a7fb822dad9aad159 to your computer and use it in GitHub Desktop.
Simple Auto Mapper
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