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

后端 未结 8 1426
执念已碎
执念已碎 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:38

    Extending Ruben's, you can get the full name like this:

    var info = System.Reflection.MethodBase.GetCurrentMethod();
    var result = string.Format(
                     "{0}.{1}.{2}()",
                     info.ReflectedType.Namespace,
                     info.ReflectedType.Name,
                     info.Name);
    

    You can add it to a static method that receives a MethodBase parameter and generates the string.

提交回复
热议问题