[英]Get full name of parameter (namespace, class, method and name) c#
我如何獲得名稱空間,類,方法和參數或變量的名稱。 例如:
namespace TheNamespace
{
class Theclass
{
void Thing()
{
string thevariable = "";
string b = thevariable.GetFullName();
// b would be equal to TheNamespace.Theclass.Thing.thevariable
}
}
}
我該怎么做
參數和變量沒有名稱空間/類名稱,因此只需組合即可獲取要查找的字符串? 可以使用反射來查找當前正在執行的方法的名稱嗎? 並獲取變量或參數的名稱 :
string b =
System.Reflection.MethodBase.GetCurrentMethod().Name + "." +
nameof(thevariable);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.