How to debug a property set in Visual Studio 2010?

Say I have this property

public ISetting Setting { get; set; } 

How can I get a breakpoint in a set? So the program pauses when something sets a value.

I'm trying to do it this way

 public IDatabaseConnectionSetting ConnectionSetting { get; set; } 

And put a breakpoint on the line set; but still it doesnโ€™t work. Red highlighting of a red dot underlines the entire declaration of properties

+6
source share
3 answers

Use the full property, not autoproperty.

Shortcut propfull

 private ISetting setting; public ISetting Setting { get { return setting; } set { setting = value; } } 

To use the code snippet shortcut, type propfull and then press TAB twice.

+5
source

There is a better solution here: Can't set breakpoints in autorun? Why?

Using Visual Studio 2008, 2010, 2012:

  • Go to the breakpoint window
  • New-> Break at Function ...
  • For get, enter: ClassName.get_CurrentFramesize ()

    For dialing, type: ClassName.set_CurrentFramesize (int)

When you reach the breakpoint, you will get "No Source", but you will get the name of the caller> in the call stack.

I found this solution here: http://social.msdn.microsoft.com/Forums/en/vsdebug/thread/b1dd0dc3-e9c1-402a-9c79-a5abf7f7286a

See also: Debug Auto Properties

+7
source

No, you canโ€™t. Automatic properties are compiled in the same way as backup storage. I think there is no reason to allow breakpoints, because somewhere you have to assign them, check your property there.

 private bool TestProperty { get; set; } 

compiled as

 [CompilerGenerated] private bool <TestProperty>k__BackingField; [CompilerGenerated] private void set_TestProperty(bool value) { this.<TestProperty>k__BackingField = value; } [CompilerGenerated] private bool get_TestProperty() { return this.<TestProperty>k__BackingField; } 
+2
source

Source: https://habr.com/ru/post/895827/


All Articles