Possible Duplicate:
get name of a variable or parameter
I want to be able to get a variable's name as a string.
This can be achieved effectively by using a parameterless lambda expression. However, this has a performance overhead, and it's not built-in functionality.
.NET 4.5 has provided CallerMemberNameAttribute
to provide a caller's name as a method argument. This gives us a built-in and better (in some cases) way to do this for specific situations.
.NET 4.5 has provided an improvement in this area for a specific context. Is there now also a better^ means to get any variable's name as a string?
As requested, here's a general usage example of what I'd like to achieve:
//Assume 'myVariable' is a local variable, member variable, static member variable, constant, parameter or even a property.
string myVariableName = ...; //This should get the string name of myVariable
^By better, I mean faster, not requiring reflection, built-into .NET or more elegant, but preferably a combination of these.