Prevent DebuggerStepThroughAttribute from applying to my non-xsd-generated partial class?

∥☆過路亽.° 提交于 2019-12-06 17:11:13

问题


I used the xsd.exe tool to generate a class based on my xml schema. It created a public partial class with DebuggerStepThroughAttribute. Well, I created another partial class file for this class to write my custom code and want to be able to step-into this code I've written but it appears the debugger is applying the step-through attribute to my partial class as well. Is there an easy way for me to step-into my code without manually removing the attribute each time I re-generate the partial class?


回答1:


  1. You can make the debugger ignore this attribute under Tools->Options->Debugger->General. Uncheck "Enable Just My Code (Managed Only)".
  2. You could also just use the partial class as a wrapper for another class/methods. The methods in the partial class would just be stubs that call the actual methods in the new class. The debugger will skip the method decorated with the attribute but still allow you to step through the class they wrap. Example below...

//

[DebuggerStepThrough]
static void DebuggerStepThroughInPartialClass()
{
   WrappedClass.NonDebuggerStepThrough();
}

class WrappedClass{
   static void NonDebuggerStepThroughInNewClass()
   {
      int bar = 0;
      bar++;
   }
}



回答2:


Best way is to simply remove the attribute lines from the generated code. The easiest way IMHO is using an alias on the command window.

example:

1) Open the command window (CTRL+A)

2) type: (VB version)

alias removenodebug Edit.Replace "(?([^\r\n])\s)*System.Diagnostics.DebuggerStepThroughAttribute\(\),\s*_\r\n(?([^\r\n])\s)*" "" /d /regex /all

3) now you have an alias to find&replace those lines on the current document. You can simply type in the command window:

removenodebug

And the attribute lines are gone.

Note: The regular expression used in this example is for VB code, but it shouldn't be too hard to convert for C#.



来源:https://stackoverflow.com/questions/1099949/prevent-debuggerstepthroughattribute-from-applying-to-my-non-xsd-generated-parti

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!