如何獲取參數或變量的命名空間、類、方法和名稱。例如:namespace TheNamespace{ class Theclass { void Thing() { string thevariable = ""; string b = thevariable.GetFullName(); // b would be equal to TheNamespace.Theclass.Thing.thevariable } }}我該怎么做
1 回答

慕無忌1623718
TA貢獻1744條經驗 獲得超4個贊
參數和變量沒有命名空間/類名,因此要獲取要查找的字符串,只需組合使用反射來查找當前正在執行的方法的名稱嗎?并獲取變量或參數的名稱:
string b = System.Reflection.MethodBase.GetCurrentMethod().Name + "." + nameof(thevariable);
- 1 回答
- 0 關注
- 72 瀏覽
添加回答
舉報
0/150
提交
取消