如何从函数内部获取函数的方法信息?



假设有一个函数GetEmployees:

public static List<Employee> GetEmployees(Dictionary<int, Department> depts, bool isFullTime)
{
// How do I get the MethodInfo of this "GetEmployees" function by writing code here?
}

我需要在该函数中获取MethodInfo的原因是我需要了解

  • 函数名称("GetEmployees"(
  • 参数的数目("2"(
  • 参数名称("depts"one_answers"isFullTime"(
  • 参数类型("System.Collections.Generic.Dictionary `2[int,Department]"one_answers"System.Boolean"(
  • 返回类型

谢谢!

我想你想要这个:

MethodInfo myMethod = MethodInfo.GetCurrentMethod();

你可以得到这样的反射参数:

ParameterInfo[] parameters = myMethod.GetParameters();

最新更新