[ vujkev @ 14.02.2009. 11:54 ] @
Code:

Public class IDNamePair
  proerty Name as string
  Property ID as integer
end class

Public class Genre
   inherits IDNamePair
end class

Public class BackEndClass
         public _List As IDNamePair()
         Private _BoxList As New Generic.Dictionary(Of Integer, CheckBox)  
       Public Property SelectedItems() As IDNamePair()
        Get
            Return (From b In _BoxList _
                               Join i In _List On i.ID Equals b.Key _
                               Where b.Value.Checked = True _
                               Select GetIDNamePair(i.ID)).ToArray


          
        End Get
        Set(ByVal value As IDNamePair())
            For Each b In _BoxList
                b.Value.Checked = False
            Next
            For Each i In value
                _BoxList.Item(i.ID).Checked = True
            Next
        End Set
    End Property

   Public Function sigleObject() As IDNamePair
        Return SelectedItems(0)
    End Function

    Private ReadOnly Property GetIDNamePair(ByVal ID As Integer) As IDNamePair
        Get
            For Each i As IDNamePair In _List
                If i.ID = ID Then
                    Return i
                End If
            Next
            Return Nothing
        End Get
    End Property
end class

public class frontEndClass
         backendclass._list = New Artists.Artist.Genre() {New Artists.Artist.Genre}
         Dim one As Artists.Artist.Genre = backendclass.sigleObject
         Dim i() As Artists.Artist.Genre = backendclass.selecteditems       
         Dim o as object = backendclass.selecteditems       

end class


Dosta sam koda obrisao pa ovo ne bi radilo kad se iskompajlira, ali greška je da backendclass.selecteditems vraća IDNamePair array koji ne mogu da konvertujem u Genre array. Kad pogledam sadržaj "O" objekta vidim da se u njemu nalazi lista Genre objekata. Zašto ne mogu da castujem u Genre kad se u njemu nalaze genre objekti? Da li se array nekako drugačije castuje?

inače backendclass.sigleObject mi se bez greške castuje u genre.

Pozdrav
[ vujkev @ 14.02.2009. 14:40 ] @
Do sad sam našao dva rešenja

Code:

 Dim i() As IDNamePair = genrelist.SelectedItems
 Dim u(i.Length - 1) As Genre
 For x As Integer = 0 To i.Length - 1
    u(x) = i(x)
 Next

 sp.GenreList = u


i

Code:

    sp.GenreList = Array.ConvertAll(Of IDNamePair, Genre)(genrelist.SelectedItems, AddressOf ConvertIDNamePair)

    Private Function ConvertIDNamePair(ByVal id As IDNamePair) As Genre
        Return CType(id, Genre)
    End Function


Drugo rešenje mi se više sviđa, ali kako napraviti neku generičku proceduru ConvertIDNamePair jer Array sa IDNamePair treba da cast-ujem u jedno 5-6 child objekata.

Sledeće rešenje ne može da prođe jer se kompajler buni da ID ne može da bude pretvoren u T (logično, zar ne)
Code:

    Private Function ConvertIDNamePair (of T)(ByVal id As IDNamePair) As T
        Return CType(id, T)
    End Function