मैं C# में कॉलिंग विधि का पूरा नाम कैसे ढूंढ सकता हूं। मैं समाधान देखा है:कॉलिंग विधि का पूरा नाम कैसे खोजें 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
लेकिन वे केवल मुझे शीर्ष स्तर दे। उदाहरण पर विचार करें:
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);
}
}
}
यह केवल आउटपुट 'मुख्य' मैं इसे कैसे मुद्रित करने के लिए 'Sandbox.Program.Main' मिल सकता है?
कोई भी पूछने से पहले कि मुझे इसका उपयोग क्यों करना है, यह एक साधारण लॉगिंग फ्रेमवर्क के लिए है जिस पर मैं काम कर रहा हूं।
संपादित
पर Matzi के जवाब जोड़ना:
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);
}
}
}
उत्पादन 'Sandbox.Program.Main' की तरह यह
के संभावित डुप्लिकेट [प्राप्त करने System.Reflection का उपयोग करते हुए एक विधि का पूरा नाम] (http://stackoverflow.com/questions/2968352/using-system-reflection-to-get-a-methods-full -नाम) – user7116