Visual Studio or Eclipse code review rule

5

I would like to know if there is an add-in for visual studio that guarantees that while I am in the development environment make some changes but when I generate the project build, this commented part is reviewed warning me that in production will not work

Example:

// DESENVOLVIMENTO
string servidor = "umaString";

// PRODUÇÃO
string servidor = "outraString";

Sometimes it is necessary to make these comments and force certain actions only in the development environment but when I build build sometimes I forget to reverse this change and I have rework

Thank you in advance

    
asked by anonymous 03.02.2016 / 20:00

1 answer

6

You can use the #if DEBUG operator for this, as demonstrated in the Microsoft documentation:

link

It is not necessary to define the DEBUG variable, because Visual Studio itself already does this, when you compile an executable as DEBUG, it already defines this variable internally, otherwise it is not defined. You can also define other variables for the many cases you need.

// exemplo definindo a variável MYTEST, que também pode ser usada para verificações adicionais
#define MYTEST
using System;
public class MyClass 
{
    static void Main() 
    {
#if (DEBUG && !MYTEST)
        Console.WriteLine("DEBUG is defined");
#elif (!DEBUG && MYTEST)
        Console.WriteLine("MYTEST is defined");
#elif (DEBUG && MYTEST)
        Console.WriteLine("DEBUG and MYTEST are defined");
#else
        Console.WriteLine("DEBUG and MYTEST are not defined");
#endif
    }
}
    
03.02.2016 / 20:06