Skip to content

Instantly share code, notes, and snippets.

@vdovinanton
Created August 9, 2019 09:02
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 vdovinanton/647c9a27b79d29dca84689fa3cdfa6b7 to your computer and use it in GitHub Desktop.
Save vdovinanton/647c9a27b79d29dca84689fa3cdfa6b7 to your computer and use it in GitHub Desktop.
public static class CopyPropertiesHelper
{
public static void CopyPropertiesTo<T>(this T from, T to)
{
var fields = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (var field in fields)
{
var value = field.GetValue(from);
field.SetValue(to, value);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment