Cómo obtener el nombre de la función actual? [duplicar]
Posible Duplicado:
¿Puede usar reflexión para encontrar el nombre del método que se está ejecutando actualmente?
C # cómo obtener el nombre del método actual de code
Por ejemplo:
void foo() {
Console.Write(__MYNAME__);
}
Print: foo
¿Es posible hacerlo en C#?
44
2 answers
Prueba esto:
System.Reflection.MethodBase.GetCurrentMethod().Name
103
Author: Raphaël Althaus,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-09-10 13:08:35
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-09-10 13:08:35
Puede comprobar el seguimiento de la pila
using System.Diagnostics;
// get call stack
StackTrace stackTrace = new StackTrace();
// get calling method name
Console.WriteLine(stackTrace.GetFrame(0).GetMethod().Name);
Pero tenga cuidado, si el método está inlineado obtendrá el nombre del método padre.
14
Author: Albin Sunnanbo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-04-13 02:25:19
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-04-13 02:25:19