public static Func<object, object> CreateGetPropertyMethod(PropertyInfo propertyInfo)
{
ParameterExpression targParam = Expression.Parameter(typeof(object), "obj");
//convert the parameter into the correct target type
UnaryExpression target = Expression.Convert(targParam, propertyInfo.DeclaringType);
//get the property
MemberExpression fieldExp = Expression.Property(target, propertyInfo);
//convert to object to return it
UnaryExpression retConvExp = Expression.Convert(fieldExp, typeof(object));
var finalLambda = Expression.Lambda<Func<object, object>>(retConvExp, targParam);
return finalLambda.Compile();
}