0

In Visual Studio(2019) while debugging I want to skip multiple lines of codes across multiple projects (C#). Is there a way to do that?

I don't want to stop the execution at the break point of that line and then manually skip by "Set to next statement" every time.

*Reason: There's a logging feature that is not setup on my local machine and I don't have admin access to do so as well.

User M
  • 319
  • 1
  • 3
  • 19
  • 2
    Or you can drag the yellow arrow next to the line numbers. – gunr2171 Nov 24 '21 at 12:42
  • Can you mock/override the logging feature with a noop class by using an extra add via dependency injection? – Silvermind Nov 24 '21 at 12:43
  • 3
    Or even simplistically in the logging method have `#if DEBUG return` ? – Caius Jard Nov 24 '21 at 12:45
  • Why do you was "without commenting it"? Do you not want to modify the logging code at all? – CodeCaster Nov 24 '21 at 12:48
  • 1
    @Him they _don't_ want to manually skip each time the code encounters the log statements. – CodeCaster Nov 24 '21 at 13:02
  • 1
    I would argue the duplicated link, probably better duplicate would be [C# if/then directives for debug vs release](https://stackoverflow.com/questions/2104099/c-sharp-if-then-directives-for-debug-vs-release) if you could add it to the dupe info. @HimBromBeere – Cleptus Nov 24 '21 at 13:11
  • gunr2171 : Wanted to get rid of the manual task Silvermind : I am not aware of the no-op class, 'll definitely take a look at it. CaiusJard : Thanks CodeCaster : I was just curious if VS had that kind of feature, since there's a conditional debugging feature to pause on the debug point if any the condition we specified is true. Cleptus : I agree with you, the duplicate link is not same as what my question was. – User M Nov 24 '21 at 13:34
  • yea sorry for posting the whrong dupe. Thanks for pointing to the correct one @Cleptus – MakePeaceGreatAgain Nov 24 '21 at 13:37

2 Answers2

1

this would do the work

 #if !DEBUG
        // Your code here
 #endif
MorenajeRD
  • 849
  • 1
  • 11
  • 27
1

There's a logging feature that is not setup on my local machine and I don't have admin access to do so as well.

Either:

  • Comment the ultimate call or method body out, or insert a return; at the first line, and don't commit it
  • Create and inject a no-op logger
  • If it's only for debugging, surround with if (!Debugger.IsAttached) { ... }
CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • Thanks @CodeCaster , I'll check what no-op logger means, but for the time being Debugger.IsAttached is a better idea for me. – User M Nov 24 '21 at 13:26