簡體   English   中英

如何從 function 中獲取函數的 MethodInfo?

[英]How to get a function's MethodInfo from within the function?

假設有一個 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?
}

我需要在這個 function 中獲取MethodInfo的原因是我需要知道

  • function 名稱(“GetEmployees”)
  • 參數個數(“2”)
  • 參數名稱(“depts”和“isFullTime”)
  • 參數類型(“System.Collections.Generic.Dictionary`2[int, Department]&”和“System.Boolean”)
  • 返回類型

謝謝!

我希望你想要這個:

MethodInfo myMethod = MethodInfo.GetCurrentMethod();

你可以像這樣得到反射的參數:

ParameterInfo[] parameters = myMethod.GetParameters();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM