//调用public static void UseCallerMemberNameAttribute(){TraceMessage(Something happened.);}public static void TraceMessage(string message,[System.Runtime.CompilerServices.CallerMemberName] strin...

//调用 public static void UseCallerMemberNameAttribute() { TraceMessage("Something happened."); } public static void TraceMessage(string message, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0) { Console.WriteLine("message: " + message); Console.WriteLine("member name: " + memberName); Console.WriteLine("source file path: " + sourceFilePath); Console.WriteLine("source line number: " + sourceLineNumber); }
输出
message: Something happened. member name: UseCallerMemberNameAttribute source file path: ... source line number: 38
示例代码
ReflectionDemo
参考资料
Get the name of the currently executing method in dotnet core
沃梦达教程
本文标题为:.net core 获得方法名


基础教程推荐
猜你喜欢
- 京东联盟C#接口测试示例分享 2022-12-02
- c#读取XML多级子节点 2022-11-05
- C#集合查询Linq在项目中使用详解 2023-06-09
- Unity shader实现多光源漫反射以及阴影 2023-03-04
- C# Winform实现石头剪刀布游戏 2023-01-11
- 使用c#从分隔文本文件中插入SQL Server表中的批量数据 2023-11-24
- C#通过GET/POST方式发送Http请求 2023-04-28
- c#中利用Tu Share获取股票交易信息 2023-03-03
- C#中类与接口的区别讲解 2023-06-04
- C# – NetUseAdd来自Windows Server 2008和IIS7上的NetApi32.dll 2023-09-20