// 获取实例 MemberExpression instanceMemberInfoExp = memberExpression.Expression as MemberExpression; FieldInfo instanceFieldInfo = instanceMemberInfoExp.Member as FieldInfo; var classInstanceExp = instanceMemberInfoExp.Expression as ConstantExpression; var instance = instanceFieldInfo.GetValue(classInstanceExp.Value);
// student 是一个学生定义,此处不展示代码 var student = new Student(); // result 第一个值为 student 对象 // result 第二个值为 student 中 Name 相关信息,通过它就可以获取 Name 的名称 Tuple<object, FieldInfo> result = TestExpression.GetFieldInfoAndInstance(() => student.Name);