在匿名方法使用MethodInfo.GetCurrentMethod() [英] Using MethodInfo.GetCurrentMethod() in anonymous methods
本文介绍了在匿名方法使用MethodInfo.GetCurrentMethod()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public static void Main(string[] args)
{
Action a = () => Console.WriteLine(MethodInfo.GetCurrentMethod().Name);
a();
}
这code会返回一个不起眼的字符串,像这样:<主> b__0
This code will return an obscure string like so: <Main>b__0
.
有没有忽略了匿名方法,并得到一个更可读的方法名称的方式?
Is there a way of ignoring the anonymous methods and get a more readable method name?
推荐答案
您可以外捕捉到它:
var name = MethodInfo.GetCurrentMethod().Name + ":subname";
Action a = () => Console.WriteLine(name);
除此之外,没有。
Other than that; no.
这篇关于在匿名方法使用MethodInfo.GetCurrentMethod()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文