[英]Get method name as String, strong typed (C#)
有沒有一種方法可以將方法的名稱強文本化為文本?
private void Do()
{
}
private Something ReturnSomething()
{
return new Something();
}
private void GenerateCode()
{
// ----------------
// Do().GetName;
// ReturnSomething().GetName;
// ----------------
// How to do this?
}
我嘗試過類似Do().ToString();
或使用Reflection
,但找不到有效的方法。
使用nameof運算符
string name = nameof(Do);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.