Imports System.IO
Imports System.Reflection
Imports System.Xml.Serialization
Imports System.ComponentModel.DataAnnotations

Namespace MainTestApplication
    Public Class Song
        Private privateName As String
        <Display(Name:="Name")>
        Public Property Name() As String
            Get
                Return privateName
            End Get
            Set(ByVal value As String)
                privateName = value
            End Set
        End Property
        Private privateAlbum As String
        <Display(Name:="Album")>
        Public Property Album() As String
            Get
                Return privateAlbum
            End Get
            Set(ByVal value As String)
                privateAlbum = value
            End Set
        End Property
        Private privateArtist As String
        <Display(Name:="Artist")>
        Public Property Artist() As String
            Get
                Return privateArtist
            End Get
            Set(ByVal value As String)
                privateArtist = value
            End Set
        End Property
        Private privateDuration As Long
        <Display(Name:="Duration")>
        Public Property Duration() As Long
            Get
                Return privateDuration
            End Get
            Set(ByVal value As Long)
                privateDuration = value
            End Set
        End Property
        Private privateSize As Long
        <Display(Name:="Size")>
        Public Property Size() As Long
            Get
                Return privateSize
            End Get
            Set(ByVal value As Long)
                privateSize = value
            End Set
        End Property
        Private privateRating As Integer
        <Display(Name:="Rating")>
        Public Property Rating() As Integer
            Get
                Return privateRating
            End Get
            Set(ByVal value As Integer)
                privateRating = value
            End Set
        End Property
    End Class

    Public Class MediaLibrary
        Public Shared Function Load() As List(Of Song)
            Dim asm = System.Reflection.Assembly.GetExecutingAssembly()
            For Each res In asm.GetManifestResourceNames()
                If res.EndsWith("songs.xml") Then
                    Using stream = asm.GetManifestResourceStream(res)
                        Dim xmls = New XmlSerializer(GetType(List(Of Song)))
                        Return CType(xmls.Deserialize(stream), List(Of Song))
                    End Using
                End If
            Next res
            Throw New Exception("Can't find 'songs.xml' embedded resource.")
        End Function
    End Class
End Namespace
