//调用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 获得方法名
基础教程推荐
猜你喜欢
- 一个读写csv文件的C#类 2022-11-06
- unity实现动态排行榜 2023-04-27
- C#类和结构详解 2023-05-30
- C# windows语音识别与朗读实例 2023-04-27
- winform把Office转成PDF文件 2023-06-14
- C# 调用WebService的方法 2023-03-09
- ZooKeeper的安装及部署教程 2023-01-22
- C# List实现行转列的通用方案 2022-11-02
- linux – 如何在Debian Jessie中安装dotnet core sdk 2023-09-26
- C#控制台实现飞行棋小游戏 2023-04-22