c# get current method name
C#[Edit]
+
0
-
0
C# get current method name
1 2 3 4 5 6string methodName = nameof(this.SomeMethodHere); // C# 6 or later // or MethodBase method = MethodBase.GetCurrentMethod(); // call it inside your method string methodName = method.Name;
[Edit]
+
0
-
0
C# get current method name
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16using System; public static class Program { private static void DoMethod() { string name = nameof(DoMethod); Console.WriteLine("Currently called method name is " + name); } public static void Main(string[] args) { DoMethod(); } }
[Edit]
+
0
-
0
C# get current method name
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18using System; using System.Diagnostics; using System.Reflection; public static class Program { private static void DoMethod() { MethodBase method = MethodBase.GetCurrentMethod(); Console.WriteLine("Currently called method name is " + method.Name); } public static void Main(string[] args) { DoMethod(); } }
[Edit]
+
0
-
0
C# get current method name
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21using System; using System.Diagnostics; using System.Reflection; public static class Program { private static void DoMethod() { StackTrace trace = new StackTrace(); StackFrame frame = trace.GetFrame(0); MethodBase method = frame.GetMethod(); Console.WriteLine("Currently called method name is " + method.Name + "."); } public static void Main(string[] args) { DoMethod(); } }