如何获取参数或变量的名称空间,类,方法和名称。例如:
namespace TheNamespace
{
class Theclass
{
void Thing()
{
string thevariable = "";
string b = thevariable.GetFullName();
// b would be equal to TheNamespace.Theclass.Thing.thevariable
}
}
}
我该怎么做
答案 0 :(得分:1)
参数和变量没有名称空间/类名,因此要获取所需的字符串,只需将Can you use reflection to find the name of the currently executing method?和get name of a variable or parameter组合在一起:
string b =
System.Reflection.MethodBase.GetCurrentMethod().Name + "." +
nameof(thevariable);