C# 如何将资源名称转换为字符串
我需要将C# 如何将资源名称转换为字符串,c#,asp.net-mvc,resources,type-conversion,C#,Asp.net Mvc,Resources,Type Conversion,我需要将ColumnName的值转换为String 转换为字符串时,返回Resources Name=Key1值='David' 我想要返回的“Key1” 如果要获取资源的名称,则未返回“David”: using System.Linq.Expressions; string name = GetName(() => Properties.Resources.Key1); static string GetName<T>(Expression<Func&l
ColumnName
的值转换为String
转换为字符串时,返回Resources
Name=Key1值='David'
我想要返回的“Key1”
如果要获取资源的名称,则未返回“David”:
using System.Linq.Expressions;
string name = GetName(() => Properties.Resources.Key1);
static string GetName<T>(Expression<Func<T>> property)
{
return (property.Body as MemberExpression).Member.Name;
}
使用System.Linq.Expressions;
string name=GetName(()=>Properties.Resources.Key1);
静态字符串GetName(表达式属性)
{
返回(property.Body作为MemberExpression).Member.Name;
}
这将使您获得“键1” 请给出一些您正在尝试了解的代码
nameof(Key1)
或Key1.Name
?
using System.Linq.Expressions;
string name = GetName(() => Properties.Resources.Key1);
static string GetName<T>(Expression<Func<T>> property)
{
return (property.Body as MemberExpression).Member.Name;
}