using System; using System.Linq.Expressions; using System.Reflection; namespace UnityStandardAssets.CinematicEffects { public static class FieldFinder { public static FieldInfo GetField(Expression> selector) { Expression body = selector; if (body is LambdaExpression) { body = ((LambdaExpression)body).Body; } switch (body.NodeType) { case ExpressionType.MemberAccess: return (FieldInfo)((MemberExpression)body).Member; default: throw new InvalidOperationException(); } } } }