In my program I have function to create log. Inside the function I check if a variable is true to continue its working or not.
private void log(string text)
{
if(LOGGING_ENABLED)
logtextbox.Text = text;
}
Is there any way to disable a function outside, without using any if inside the function or in parameter, to disable all occurrences of function in program.
You can use the ConditionalAttribute. Calls to a method with this attribute are compiled out depending on whether the condition is defined. For example:
Calls to this method will show up in Debug mode, but will not be in your code in Release mode, because the DEBUG condition is only defined during Debug mode.
Edit: In response to some of your questions, I’d recommend taking a look at the API Reference page. It has some pretty simple examples and explanations on how to use the attribute and its effects.