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 Answer 1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.