Visual Studio Debugger - Automatic Variable Assignment

I am working on a project with several developers, and the developed application is launched through the launch application, which transmits parameters such as login, their location, etc. Now, when I debug the application, I set a breakpoint on the code that parses the input parameters and assigns the username variable my username, etc.

I could hard code these values, but:

  • I think this is bad practice.
  • I am worried that the file will be checked in our VCS and will have catastrophic ripple effects.
  • Several developers are working on the project, so hard coding my name, location assignments, etc. really not an option.
  • I cannot make the file read-only, because it is under active development, and I constantly need to update the version of the specified file.

My question is:

  • Is there a built-in method or extension to AUTOMATICALLY assign variables to values ​​in debug mode. Right now I am highlighting a variable and typing my text, can it be automated?

Thank you in advance

+6
source share
4 answers

When I encounter such situations, I usually combine conditional compilation and an environment / reg variable. You can use these storage mechanisms to place your information without hard coding it in the application.

#if DEBUG
if ( null != Environment.GetVariable("CUSTOM_INFO")) {
  userName = Environment.GetVariable("CUSTOM_USERNAME");
  ...
}
#endif

, . , , .

+1

JaredPar, .

(, ) . (, IF DEBUG) .

, .

0

. -, , , 2009 . , nunit testdriven.net. , .

0

, Trace Points.

, . ( alt + F9, c Tab ). , , .

E.g.:

2 + 2 = {2 + 2}

"2 + 2 = 4". :

{myVar = 5}

.
, , Void:

public static class HelperFunctions
{
    public static void AssignTo<T>(this T value, out T variable)
    {
        variable = value;
    }
}

:

{"new value".AssignTo(out def)}

Ouput ( , ).

, , , , , . , "" "", "" - .

Edit

Visual Studio 2013, 2019 (, ) : https://developercommunity.visualstudio.com/content/problem/715716/variables-cannot-be-assigned-in-breakpoint-conditi.html

0
source

All Articles