I have one application in which I need to make code changes almost all the time (changing cryptographic procedures, etc.), so my idea is that every time I make changes, all debugging parameters and variables are activated. I don’t want to comment and uncomment the code all the time, so my question is about simple lines of code that will only run in debug mode. ¿How can I achieve this?
You can use the conditional code section:
#if DEBUG //Your code goes here. #endif
[Conditional("DEBUG")] .
[Conditional("DEBUG")]
:
[Conditional("DEBUG")] private void YourFunction() { }
.
http://www.csharphelp.com/archives/archive36.html
, :
#if DEBUG Console.WriteLine("DEBUG is defined"); #else Console.WriteLine("DEBUG is not defined"); #endif
. :
#if DEBUG // Lines here are only compiled if DEBUG is defined, like in a Debug build. #else // Lines here are only compiled if DEBUG is not defined, like in a Release build. #endif
[Conditional("DEBUG")] public void DoDebugOnly() { // Whatever }
DoDebugOnly() DEBUG.
. TRACE - , Visual Studio, , , :
#define FOO #if FOO // Lines here are only compiled if FOO is defined. #endif
Depending on what you are trying to do, you might consider a logging structure such as log4net or Protocol Logging . They will allow you to leave debugging messages in your code, but will only output them if the external configuration file says.
If you want to add / remove code that actually executes logic, go with the other answers.
Source: https://habr.com/ru/post/1717980/More articles:https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1717975/how-much-information-in-error-messages-to-regular-users&usg=ALkJrhho0ydnDjiqkobjmBfzCl2p6tcFZQIs there a standard term for a class that contains only data, not logic? - terminologyHow to autoload extended classes? - phpTTURLResponse - nil - iphoneРазмер шрифта ячейки UITableView - iphoneResources for WPF and Silverlight in the same assembly - resourceshttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1717982/oracle-normalized-fields-to-csv-string&usg=ALkJrhjyaxjscb1e7JV8LP5Abqgcs3fhbgHow do I know if an instance of a class exists in memory? - javaAnonymous inner class in groovy - javaAny way to read JAAS configuration file from memory - javaAll Articles