65.9K
CodeProject is changing. Read more.
Home

Preventing stubbed methods from being released

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.90/5 (3 votes)

Oct 15, 2011

CPOL
viewsIcon

9653

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.
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. :)