Skip to content

Instantly share code, notes, and snippets.

@ADelRosarioH
Created April 28, 2015 13:45
Show Gist options
  • Save ADelRosarioH/3f98f708c54c9beb2982 to your computer and use it in GitHub Desktop.
Save ADelRosarioH/3f98f708c54c9beb2982 to your computer and use it in GitHub Desktop.
Simple Object to Object Mapper.
public sealed class Mapper
{
public delegate void Rule<F, T>(F from, T to)
where F : class
where T : class;
public static T Map<F, T>(F primary, params Rule<F, T>[] rules)
where F : class
where T : class
{
T secondary = Activator.CreateInstance<T>();
foreach (var rule in rules)
{
rule.Invoke(primary, secondary);
}
return secondary;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment