How to

get calling method

Published: 14. January 2009 | Updated: 14. January 2009
License: Microsoft Public License (MS-PL)
Categories: Debug, Framework » Reflection
Tags: C# Debug Reflection
Was this snippet helpful for you? YESYES / NONO

Import namespaces

using System.Diagnostics;
using System.Reflection;

Code

StackTrace stackTrace = new StackTrace();
StackFrame stackFrame = stackTrace.GetFrame(1);
MethodBase callingMethod = stackFrame.GetMethod();
Console.WriteLine("{0}: {1}", callingMethod.DeclaringType, callingMethod.Name);
Send us feedback about this snippet »



Related Snippets: