Correct posture vs plus debugging code

For convenience, we will add some debugging code in the system, such as automatic login, this will save a lot of energy and time, but with the right posture,

First heavy position: Packing Notes

I think some people add debugging code (such as automatic login), and then packed in time vs commented, so the operation is saved. But we should always remember to remove the code, this may be a major event.

            // comments in the code, remove the official release 
            String UserName = " Administrator " ;
             String Password = " 123 " ; 
            The AutoLogin (UserName, Password);

Second heavy posture: a preprocessor directives #if

When the compiler encounters C # #if instruction ultimately #endif instruction, only when the symbol definition specifies that only between these instructions compiled code. So you can use debug symbols to distinguish the current build system is released or debugging

#if DEBUG

            string UserName = "administrator";
            string Password = "123";
            AutoLogin(UserName, Password);
#endif

 

The third gesture weight: Custom #if preprocessor command sign

To pre-specified above, meet with debugging code does not affect the official release version of the system. However, it was possible to generate formal installation package also debug mode. Such a practice we do not comment. Encountered such a situation, we can not use a second heavy posture. At this time we can customize the specified symbol.

1. First, we click on the solution configuration, in the drop-down box, select " Configuration Manager "

 

 2, in the pop-up Configuration Manager window active solution configuration at select New Item

 

 3, in the pop-up New Solution Configuration Name window, enter your name, we want to copy debug configuration, so from here copy the configuration we choose to debug, create a new project configuration tick, click OK

 At this time we can see our new solution configurations in solution configuration

 

 4, choose our new solution configuration, right-start the project, select Properties in the pop-up window, select generating item, enter conditional compilation symbol of our self-defined conditional compilation symbol under conventional items (note: different conditional compilation symbols separated by a colon), the lower figure LocalTest is our new symbol.

 

 5, at this time we can use conditional compilation symbol to distinguish our definition of debugging and generated.

#if LocalTest

            string UserName = "administrator";
            string Password = "123";
            AutoLogin(UserName, Password);
#endif

 

The above said though very basic, but also very important. Smart work can improve work efficiency, usually if there are some lessons can also be raised in the comments, thank you!

Guess you like

Origin www.cnblogs.com/ssvip/p/11593461.html