我不想再传递 nameof 了
内容简介:
有的时候抛出一个异常,我们需要知道是哪个方法抛出的异常。那么,我们可以通过传递 nameof 来获取调用者的方法名。但是,感觉很烦,每次都要传递 nameof。那么,有没有更好的方法呢?
CallerLineNumberAttribute
获取调用者的行号。
using System;
using System.Runtime.CompilerServices;
public static class Program
{
public static void Main()
{
TraceMessage("Something happened.");
}
...
查看原文
暂无评论...