I use this method to get the value of a property in a method:
public static T Decrypt<T>(Func<T> prop, string username, string password)
{
T value = prop();
//do cool stuff with t
return value;
}
I'm looking for a way to do the other way arround, set the value of my property
public static void Encrypt<T>(Func<T> prop, T value, string username, string password)
{
//do stuff with value
??? set prop ???
}
I've searched and tried Expressions, but cloud not get it to work:
public static void Encrypt<T>(Expression<Func<T>> property, T value, string username, string password)
{
//do stuff with value
var propertyInfo = ((MemberExpression)property.Body).Member as PropertyInfo;
propertyInfo.SetValue(property, value);
}