Skip to content

Instantly share code, notes, and snippets.

@bradoyler
Created May 30, 2018 20:50
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 bradoyler/729d49ef8e57ab8190f950a2fc2c0c8b to your computer and use it in GitHub Desktop.
Save bradoyler/729d49ef8e57ab8190f950a2fc2c0c8b to your computer and use it in GitHub Desktop.
public T ObjectAssign(T source)
{
Type t = this.GetType();
var properties = t.GetProperties().Where(prop => prop.CanRead && prop.CanWrite);
foreach (var prop in properties)
{
var value = prop.GetValue(source, null);
if (value != null)
prop.SetValue(this, value, null);
}
return this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment