Come posso trovare il nome completo di un metodo di chiamata in C#. Ho visto soluzioni:Come trovare il metodo FULL del metodo di chiamata C#
How I can get the calling methods in C#
How can I find the method that called the current method?
Get Calling function name from Called function
Ma solo mi indica il livello superiore. Si consideri l'esempio:
namespace Sandbox
{
class Program
{
static void Main(string[] args)
{
test();
}
static void test()
{
var stackTrace = new StackTrace();
var methodBase = stackTrace.GetFrame(1).GetMethod();
Console.WriteLine(methodBase.Name);
}
}
}
Emette semplicemente 'principale' Come posso ottenere per stampare 'Sandbox.Program.Main'?
Prima che qualcuno inizi a chiedere perché devo usarlo, è per un semplice framework di registrazione su cui sto lavorando.
EDIT
Aggiunta sulla risposta del Matzi:
ecco la soluzione:
namespace Sandbox
{
class Program
{
static void Main(string[] args)
{
test();
}
static void test()
{
var stackTrace = new StackTrace();
var methodBase = stackTrace.GetFrame(1).GetMethod();
var Class = methodBase.ReflectedType;
var Namespace = Class.Namespace; //Added finding the namespace
Console.WriteLine(Namespace + "." + Class.Name + "." + methodBase.Name);
}
}
}
Produce 'Sandbox.Program.Main' come dovrebbe
possibile duplicato del [using System.Reflection per ottenere un metodo Nome completo] (http://stackoverflow.com/questions/2968352/using-system-reflection-to-get-a-methods-full -name) – user7116