Using System.Reflection to Get a Method's Full Name

后端 未结 8 1421
执念已碎
执念已碎 2020-12-13 06:00

I have a class that look like the following:

public class MyClass
{

...

    protected void MyMethod()
    {
    ...
    string myName = System.Reflection.M         


        
8条回答
  •  春和景丽
    2020-12-13 06:44

    And to get the full method name with parameters:

    var method = System.Reflection.MethodBase.GetCurrentMethod();
    var fullName = string.Format("{0}.{1}({2})", method.ReflectedType.FullName, method.Name, string.Join(",", method.GetParameters().Select(o => string.Format("{0} {1}", o.ParameterType, o.Name)).ToArray()));
    

提交回复
热议问题