简体   繁体   English

DebuggerStepThrough属性是否等同于属性?

[英]DebuggerStepThrough attribute equivalent for properties?

The DebuggerStepThrough attribute instructs the VS debugger to step through code instead of stepping into the code. DebuggerStepThrough属性指示VS调试器单步执行代码,而不是单步执行代码。

DebuggerStepThroughAttribute Class DebuggerStepThroughAttribute类

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. 我的问题是,是否有与该属性等效的属性可用于Property成员?,因为我的属性的设置器会引发异常,并且我不想在发生这种情况时中断设置器的代码块。

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. 我知道一种解决方案是将setter的代码移动到单个方法,然后将DebuggerStepThrough属性设置为该方法,但是我只是在寻求一种可能的替代方法,即应用另一个属性而不是移动代码。

You can actually apply this attribute directly to the getter and setter. 实际上,您可以直接将此属性应用于getter和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#. 对于C#,这是相同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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