jeudi 25 février 2016

get and set object property using Expression trees instead of Reflection

I would like to dynamically get and set an objects properties as follows:

public class Person
{
    public string Name {get; set; }
}

public class Testing
{
    public void Run()
    {
        var p = new Person();

        SetValue(p, "Name", "Henry");

        var name = GetValue(p, "Name");
    }
}

Please could I get help creating the GetValue and SetValue methods using dynamic method (or expression trees)?

I am intending to save compiled expressions in a dictionary, to speed up future get/set calls.





Aucun commentaire:

Enregistrer un commentaire