简体   繁体   中英

DebuggerStepThrough attribute equivalent for properties?

The DebuggerStepThrough attribute instructs the VS debugger to step through code instead of stepping into the code.

DebuggerStepThroughAttribute Class

My question is, is there an equivalent of this attribute to use it for a Property member?, because the setter of my property can throw an exception, and I don't want to break in the setter's code-block when that happens.

I know one solution is to move the setter's code to a single method and then set the DebuggerStepThrough attribute to that method, but I'm just asking for a possible alternative applying another attribute instead of moving code.

You can actually apply this attribute directly to the getter and setter.

Dim firstName, lastName As String 
Property fullName() As String 
    <DebuggerStepThrough>
    Get 
      If lastName = "" Then 
          Return firstName
      Else 
          Return firstName & " " & lastName
      End If 

    End Get 

    <DebuggerStepThrough>
    Set(ByVal Value As String)
        Dim space As Integer = Value.IndexOf(" ")
        If space < 0 Then
            firstName = Value
            lastName = "" 
        Else
            firstName = Value.Substring(0, space)
            lastName = Value.Substring(space + 1)
        End If 
    End Set 
End Property

This is the same for C#.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM