2021年3月31日星期三

How to get a function's MethodInfo FROM WITHIN THE FUNCTION?

Suppose there is a function 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?  }  

The reason I need to get the MethodInfo inside this function is that I need to know

  • The function name ("GetEmployees")
  • The number of parameters ("2")
  • The parameter names ("depts" and "isFullTime")
  • The parameter types ("System.Collections.Generic.Dictionary`2[int, Department]&" and "System.Boolean")
  • The return type

I am sure you will ask me, "You already have the source code of this function, it is plainly in front of you, why do you need to write code to find it out?" My answer is, "Please just trust me that I have a good reason to do so." Thanks!

https://stackoverflow.com/questions/66897156/how-to-get-a-functions-methodinfo-from-within-the-function April 01, 2021 at 09:01AM

没有评论:

发表评论