Using reflection to get the instance name of a variable
-
Is there a way to use reflection to get the variable name that a method is called on ? For instance ...
class foo { public override string ToString() { return GetType().toString() + " " + GetType().??? VaraibleName ???; } } . . . foo myFoo = new foo(); Console.WriteLine( myFoo.toString());
Should ouput foo myFoo -
Is there a way to use reflection to get the variable name that a method is called on ? For instance ...
class foo { public override string ToString() { return GetType().toString() + " " + GetType().??? VaraibleName ???; } } . . . foo myFoo = new foo(); Console.WriteLine( myFoo.toString());
Should ouput foo myFooI wouldn't expect you could because variable names are stored only in your code, once you've compiled they go away. You could tell things like class name, etc., but not variable name.
-
I wouldn't expect you could because variable names are stored only in your code, once you've compiled they go away. You could tell things like class name, etc., but not variable name.
-
That figures. I just wanted to do some screen dumps while I develop/run and see the values of the variables. I was hoping the variable names could be auto-generated. Anyway, thank you for the quick reply.
RascalRobot wrote:
wanted to do some screen dumps while I develop/run and see the values of the variables
It's called the debugger, it comes with VS:doh:
only two letters away from being an asset
-
RascalRobot wrote:
wanted to do some screen dumps while I develop/run and see the values of the variables
It's called the debugger, it comes with VS:doh:
only two letters away from being an asset
-
That would work if I were allowed to install VS on the target machine. I am only allowed to install the final .exe on the target which is not connected to our network. In other words, no debug tools allowed. :sigh:
There is the thing about being specific in your request. You said, "while I **develop/**run". To me this implied a development environment. Your left with trace output, event logs, remote debugging, etc.
only two letters away from being an asset
-
That would work if I were allowed to install VS on the target machine. I am only allowed to install the final .exe on the target which is not connected to our network. In other words, no debug tools allowed. :sigh:
Two thoughts - one you could either use Tracing or you could do the following: http://blogs.msdn.com/yosit/archive/2003/06/20/9024.aspx[^]
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before. -
Is there a way to use reflection to get the variable name that a method is called on ? For instance ...
class foo { public override string ToString() { return GetType().toString() + " " + GetType().??? VaraibleName ???; } } . . . foo myFoo = new foo(); Console.WriteLine( myFoo.toString());
Should ouput foo myFoopossible if and only if it is a class level variable! it becomes a fields, if it just has a scope in a method alone, 100 % not possible experiencing the experience