Skip to content

Instantly share code, notes, and snippets.

@solrevdev
Created June 24, 2021 11:05
Show Gist options
  • Select an option

  • Save solrevdev/41877b2581d464b09371496ddf4406f5 to your computer and use it in GitHub Desktop.

Select an option

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
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