I'm interested to understand how are implemented LabelFor, EditorFor... methods that accept lambda expressions in MVC.
Lets say I have a class Person and I want to print the name and the value of a property. How must be implemented Label() and Editor() methods?
class Person
{
public int Id { get; set; }
}
void Label(Expression<Func<Person, int>> expression)
{
//...
}
void Editor(Expression<Func<Person, int>> expression)
{
//...
}
public void Test()
{
Person p = new Person
{
Id = 42
};
Label(x => x.Id ); // print "Id"
Editor(x => x.Id); // print "42"
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire