How would you, in C#, determine the name of the variable that was used in calling a method?
Example:
public void MyTestMethod1()
{
string myVar = "Hello World";
MyTestMethod2(myVar);
}
public void MyMethod2(string parm)
{
// do some reflection magic here that detects that this method was called using a variable called 'myVar'
}
I understand that the parameter might not always be a variable, but the place I am using it is in some validation code where I am hoping that the dev can either explicitly state the friendly name of the value they are validating, and if they don't then it just infers it from the name of the var that they called the method with...