Debugging automatic properties

自闭症网瘾萝莉.ら 提交于 2019-11-26 03:48:35

问题


Is there any way to set breakpoint on setter/getter in auto-implemented property?

int Counter { get; set; }

Other than changing it to standard property (I\'m doing it in this way, but to do that I have to change and recompile whole project)


回答1:


Using Visual Studio 2008, 2010, 2012, 2013:

  1. Go to the Breakpoint window
  2. New -> Break at Function…
  3. For the get, type: ClassName.get_Counter()

    For the set, type: ClassName.set_Counter(int)

You'll get a "No Source Available" when the breakpoint is hit, but you'll get the calling location in the call stack.

I found this solution here on MSDN




回答2:


If I was you, I'd temporarily make the property a standard one backed by an internal field...set your breakpoints, and then you can change it back after.




回答3:


This question is very old but it is worth that it just works in VS 2015.

https://blogs.msdn.microsoft.com/visualstudioalm/2014/11/14/set-breakpoints-on-auto-implemented-properties-with-visual-studio-2015/

class X {
  public string name {
    set;
    get; // setting a breakpoint here will break in VS 2015!
  }
}



回答4:


Set Breakpoints where you are setting property or getting property, No other way.

you can do this by Find All References options

And Since it is only storing values and do not have any code in setter part so what do you debug?



来源:https://stackoverflow.com/questions/4408110/debugging-automatic-properties

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