What i currently use
public static void MapObjectPropertyValues(object e1, object e2)
{
foreach (var p in e1.GetType().GetProperties())
{
if (e2.GetType().GetProperty(p.Name) != null)
{
p.SetValue(e1, e2.GetType().GetProperty(p.Name).GetValue(e2, null), null);
}
}
}
I want to pass a third parameter, a generic list of types that i want to exclude from the mapping. For example strings and booleans. And check if p is of a type in the list. Any help is appreciated, thanks!
You could use the
p.PropertyTypeproperty to exclude assignment if the types match exactly.