views:

45

answers:

2

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 String
        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.

+2  A: 

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

to do this in Visual Basic,

<DebuggerDisplay("Name: {Name}")>
Axarydax
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.
marco.ragogna
In DebuggerDisplay show a property that does your complex logic then
Axarydax
+1  A: 

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
Hans Passant
great solution, I didn't know this trick XD
marco.ragogna