Skip to content

Instantly share code, notes, and snippets.

@amirci
Created September 15, 2011 17:28
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 amirci/1219900 to your computer and use it in GitHub Desktop.
Save amirci/1219900 to your computer and use it in GitHub Desktop.
Using expression to pass property names
// Given the class
class PropertyId {
public int Id {get;set;}
public int StateCode {get;set;}
}
var id = new PropertyId { Id = 1, StateCode = "NY" };
// call the method
SetProperty(id => id.StateCode, "CA");
// then on the method declaration
public void SetProperty(Expression<Functor<object>> expr, object value) {
var member = exp.Body as MemberExpression;
var name = member.Member.name;
.
.
.
.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment