Func<T, TField> GetFunc<T, TField> (this FieldInfo fieldInfo) {
var instanceParameter = Expression.Parameter (typeof (T), "instance");
var fieldExpression = Expression.Field (instanceParameter, fieldInfo);
var lambda = Expression.Lambda<Func<T, TField>> (fieldExpression, instanceParameter);
return lambda.Compile ();
}
I wrote this method to get this lambda expression.
return (T instance) => instance.[fieldInfo.Name];
But how do I write the method to get this lambda expression?
return (T instance) => ref instance.[fieldInfo.Name];