Click here to Skip to main content
15,885,546 members
Articles / Programming Languages / C#
Alternative
Tip/Trick

Preventing stubbed methods from being released

Rate me:
Please Sign up or sign in to vote.
4.90/5 (3 votes)
15 Oct 2011CPOL 9.2K   1   2
Very nice tips indeed!A somewhat different approach to this might be to use the Debugger.IsAttached[^] static property.Though this works somewhat different.if (System.Diagnostics.Debugger.IsAttached){ // This code executes when starting from VS either in release or debug...
Very nice tips indeed!
A somewhat different approach to this might be to use the Debugger.IsAttached[^] static property.
Though this works somewhat different.
C#
if (System.Diagnostics.Debugger.IsAttached)
{
   // This code executes when starting from VS either in release or debug mode.
}
else
{
   // This code executes when starting from outside VS either in release or debug mode.
}

This looks more .NETish, but also performs differently as you can see.
I have used it many times for debugging purposes (for example, giving a value to a variable only for debugging).
Though not really a substitute for the above tips, I thought I should include this for completeness. :)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO JUUN Software
Netherlands Netherlands
Sander Rossel is a Microsoft certified professional developer with experience and expertise in .NET and .NET Core (C#, ASP.NET, and Entity Framework), SQL Server, Azure, Azure DevOps, JavaScript, MongoDB, and other technologies.

He is the owner of JUUN Software, a company specializing in custom software. JUUN Software uses modern, but proven technologies, such as .NET Core, Azure and Azure DevOps.

You can't miss his books on Amazon and his free e-books on Syncfusion!

He wrote a JavaScript LINQ library, arrgh.js (works in IE8+, Edge, Firefox, Chrome, and probably everything else).

Check out his prize-winning articles on CodeProject as well!

Comments and Discussions

 
GeneralFor great effect, you can combine this with other useful met... Pin
Julien Villers15-Oct-11 2:00
professionalJulien Villers15-Oct-11 2:00 
GeneralRe: Debugger.Break(), yeah. Use it from time to time when breakp... Pin
Sander Rossel15-Oct-11 2:06
professionalSander Rossel15-Oct-11 2:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.