[英]Get method name as String, strong typed (C#)
Is there a way to get the name of a method as text, strongly typed? 有没有一种方法可以将方法的名称强文本化为文本?
private void Do()
{
}
private Something ReturnSomething()
{
return new Something();
}
private void GenerateCode()
{
// ----------------
// Do().GetName;
// ReturnSomething().GetName;
// ----------------
// How to do this?
}
I tried something like Do().ToString();
我尝试过类似Do().ToString();
or by using Reflection
, but I couldn't find something that worked. 或使用Reflection
,但找不到有效的方法。
使用nameof运算符
string name = nameof(Do);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.