Skip to content

Instantly share code, notes, and snippets.

@davefancher
Created November 10, 2016 04:04
Show Gist options
  • Save davefancher/4985283e60044327826b80adad91e23f to your computer and use it in GitHub Desktop.
Save davefancher/4985283e60044327826b80adad91e23f to your computer and use it in GitHub Desktop.
public static T SetProperty<T, U>(
this T @this,
Expression<Func<T, U>> propertyExpression,
U value)
{
propertyExpression
.Body
.ConvertTo<MemberExpression>()
.Member
.Name
.Map(@this.GetType().GetProperty)
.SetValue(@this, value);
return @this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment