Grade, although this may be more of a problem than it costs.
ASP.Net MVC often uses expressions to retrieve property information in a strongly typed way. The expression is not necessarily evaluated; instead, it is parsed for its metadata.
MVC; , Microsoft.
, :
public class Foo
{
public string Bar {
get;
set;
}
}
public TProperty EvaluateProperty<TProperty>( Expression<Func<Foo, TProperty>> expression ) {
string propertyToGetName = ( (MemberExpression)expression.Body ).Member.Name;
return expression.Compile()( null );
}
( ):
var foo = new Foo { Bar = "baz" };
string val = EvaluateProperty( o => foo.Bar );
foo = new Foo { Bar = "123456" };
val = EvaluateProperty( o => foo.Bar );