mercredi 31 mars 2021

C# reflection: how to get a function's MethodInfo FROM WITHIN THIS 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!





Aucun commentaire:

Enregistrer un commentaire