Created
June 24, 2021 11:05
-
-
Save solrevdev/41877b2581d464b09371496ddf4406f5 to your computer and use it in GitHub Desktop.
Get Class and MethodName for current method in C# for example Program.Main.TestMethod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Reflection; | |
| namespace web | |
| { | |
| public class Startup | |
| { | |
| public static void Main(string[] args) | |
| { | |
| if (args?.Length > 0) | |
| { | |
| Console.WriteLine($"▲ Found {args?.Length} params to process"); | |
| } | |
| Console.WriteLine("Test"); | |
| TestMethod(); | |
| } | |
| static void TestMethod() | |
| { | |
| var @this = $"[{MethodBase.GetCurrentMethod().DeclaringType}.{MethodBase.GetCurrentMethod().Name}]"; | |
| Console.WriteLine(@this); | |
| } | |
| } | |
| } | |
| // | |
| // outputs this: | |
| // | |
| // Test | |
| // [web.Startup.TestMethod] | |
| // |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment