利用反射和lambda获取变量名字

梦想游戏人
目录:
Unity
void Start() { Debug.LogError(GetName(() => test_member)); } int test_member = 0; string GetName<T>(Expression<Func<T>> exp) { var mem = exp.Body as MemberExpression; var ret = mem.Member.Name; return ret; }
Scroll Up