private static void PrintOperationName() { string operationName = OperationContext.Current.IncomingMessageHeaders.Action; Console.WriteLine("Current Operation Name: " + operationName); }
private static void PrintOperationName() { var stackTrace = new StackTrace(); var methodBase = stackTrace.GetFrame(1).GetMethod(); Console.WriteLine("Current Operation Name: " + methodBase.Name); }This code example shows how to use the GetOperationName method to retrieve the name of the current method being executed in a C# class. It uses the StackTrace and GetFrame methods to get the current method base and then retrieves its name. Package library: None (part of the System namespace)