Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

Preventing stubbed methods from being released

4.90/5 (3 votes)
15 Oct 2011CPOL 9.7K  
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)