C# developers often need to determine the method of calling the current execution method. Although can obtain the information of the current method, to obtain the information of the call method, you need to learn more about the stack tracking.
Traversing the stack tracking System.Reflection.MethodBase.GetCurrentMethod()
Analysis of the stack tracking seems feasible, but there is a more concise and direct method. You can get the information of the call set, and similar methods are also applicable to the method.
Traveling up the stack Assembly.GetCallingAssembly()
method, you can trace the stack first level and obtain the call method. Then, you can use the name of the call method. sample code
System.Diagnostics.StackTrace
The following code demonstrates the usage of this technology: GetFrame(1)
GetMethod().Name
The above is the detailed content of How Can I Get the Name of the Method That Called the Current Method in C#?. For more information, please follow other related articles on the PHP Chinese website!