开发者

Overrided ToString doesn't show in debug

I have a collection similar to:

Public Class MyCollection
    Inherits ObservableCollection(Of MyCollection)

    Private _Name As String

    Public Property Name() As String
        Get
            Return _Name
        End Get
        Set(ByVal value As String)
            _Name = value
        End Set
    End Property

    Public Overrides Function ToString() As Str开发者_如何学Going
        Return "Name: " & _Name
    End Function

End Class

I have overrided ToString method in order to help in debug, but it doesn't show up.

In the code that follow if, during debug, I move the mouse over coll it shows me Count = 0

Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded    
        Dim coll As New MyCollection    
        coll.Name = "Test"        
    End Sub

Do you know what could be the problem?

EDIT: I know that I can use DebuggerDisplay, but unfortunately it is very limited. The class in reality is quite complex and I need to have the possibility to define a logic in what I show during debugging, if possible.


You would need to set up a Debugger attribute for the class MyCollection - in C# I'd do [DebuggerDisplay("Name:={Name}")]

  • see http://blogs.interknowlogy.com/adamcalderon/archive/2006/08/03/3612.aspx

to do this in Visual Basic,

<DebuggerDisplay("Name: {Name}")>


The DebuggerDisplay attribute is your problem, your class inherits one specified on the Collection(Of T) base class. Getting it to start using your ToString() override again is simple, just make it look like this:

<DebuggerDisplay("{ToString()}")> _
Public Class MyCollection
  Inherits ObservableCollection(Of MyElementClass)
  REM etc...
End Class
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜