views:

363

answers:

2

I want to perform following operation in .NET Compact Framework. I am looking for Calling Method type.

http://www.csharp-examples.net/reflection-calling-method-name/

.NET Compact Framework doesn't support StackFrame class. Also, GetCurrentMethod() is not available in MethodBase class.

A: 

As you're finding, the Compact Framework is just that - compact. Not everything from the full framework is available, and this is an example of that. There simply is no way to determine the calling method unless you're in an Exception handler and can look at the call stack there (and even then getting the method name isn't as straightforward as one would like).

ctacke
+1  A: 

Try throwing an exception then check it's StackTrace property.

try
   {
       throw new Exception();
   }
catch(Exception ex)
   {
       Console.Write(ex.StackTrace);
   }

It will give something like

"at NumericTextBoxControl.NumericalInput..ctor()\r\nat Custom_Numeric_Input.frmTestApplication.InitializeComponent()\r\nat Custom_Numeric_Input.frmTestApplication..ctor()\r\nat Custom_Numeric_Input.Program.Main()\r\n"

which you can parse, split and use reflection on.

Wesam Abdallah

related questions