C#中根据变量获取变量名字符串
- 摘要:///<summary>///获取当前变量的变量名字符串///调用:GetVarName(p=>test.str1);返回"str1"///</summary>///<paramname="exp"></param>///<returns></returns>publicstaticstringGetVarName(System.Linq.Expressions.Expression<Func<
- 标签:C# 字符串
- /// <summary>
- ????????/// 获取当前变量的变量名 字符串
- ????????/// 调用:GetVarName(p=>test.str1); 返回 "str1"
- ????????/// </summary>
- ????????/// <param name="exp"></param>
- ????????/// <returns></returns>
- ????????public
static
string GetVarName(System.Linq.Expressions.Expression<Func<string, string>> exp)
- ????????{
- ???????????return ((System.Linq.Expressions.MemberExpression)exp.Body).Member.Name;
- ????????}