//调用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# 构造方法(函数) 2023-03-03
- C#使用SQL DataAdapter数据适配代码实例 2023-01-06
- C#使用Chart绘制曲线 2023-05-22
- C#中参数的传递方式详解 2023-06-27
- C#使用NPOI将excel导入到list的方法 2023-05-22
- 如何用C#创建用户自定义异常浅析 2023-04-21
- C#实现归并排序 2023-05-31
- C#执行EXE文件与输出消息的提取操作 2023-04-14
- C# TreeView从数据库绑定数据的示例 2023-04-09
- Unity虚拟摇杆的实现方法 2023-02-16
