Created
September 15, 2011 17:28
-
-
Save amirci/1219900 to your computer and use it in GitHub Desktop.
Using expression to pass property names
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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