How can I achieve this without using compilation (), but only with normal reflection?
var value = Expression.Lambda(memberExpression).Compile().DynamicInvoke();
I want this to be able to run on an IPhone (MonoTouch), which does not allow dynamic compilation.
UPDATE: There is more context. This is the code I'm working on:
if (expression.Expression is ConstantExpression) { var constantExpression = (ConstantExpression)expression.Expression; var fieldInfo = constantExpression.Value.GetType().GetField(expression.Member.Name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (fieldInfo != null) { return fieldInfo.GetValue(constantExpression.Value); } { var propertyInfo = constantExpression.Value.GetType().GetProperty(expression.Member.Name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (propertyInfo != null) { return propertyInfo.GetValue(constantExpression.Value, null); } } } else { return Expression.Lambda(expression.Expression).Compile().DynamicInvoke(); }
As you can see, the code in the if block does not use compilation at run time to get the value. My goal is that the code in the else block also does not use compilation at runtime.
source share