T4 tip (debug)

2010/08/15

tags: , , ,
no comments

T4 tip (debug)

while I was writing the post on T4 debugging (here),

I had show how to use System.Diagnostics.Debugger.Break()

in order of getting the debugger stop.

 

actually there is 2 problem with this pattern:

  • the break point remain active while no debugger is attached.
  • it cause VS to crash when ever saving the t4, when the debugger doesn’t attached.
Solution

we can overcome those issues by changing the pattern to match the following:

Code Snippet
  1. if (System.Diagnostics.Debugger.IsAttached)
  2.     System.Diagnostics.Debugger.Break();

 

Summary

using the IsAttached pattern will prevent the breaking point activation

as long as the no debugger is attached.

 

kick it on DotNetKicks.com Shout it

Digg This
Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>