1

How would I get the namespace, class, method and name of a parameter or variable. For example:

namespace TheNamespace
{
    class Theclass
    {
        void Thing()
        {
            string thevariable = "";
            string b = thevariable.GetFullName();
            // b would be equal to TheNamespace.Theclass.Thing.thevariable
        }
    }

}

How would I do this

1 Answers1

1

Parameters and variables don't have namespace/class name so to get string you are looking for you simply combine Can you use reflection to find the name of the currently executing method? and get name of a variable or parameter:

string b = 
       System.Reflection.MethodBase.GetCurrentMethod().Name + "." + 
       nameof(thevariable);
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179