title: Casting Generic Interface to base type
body: <p>I'm struggling to get this hierarchy working with generics. The problem is that Items is generic, specified at the inheritance level, therefore I cannot cast back to BaseItem, i.e. casting from SpecialItem(Of ExtraSpecialItem) to IItemHost(Of BaseItem) when SpecialItem inherits BaseGroup, as BaseGroup implements IItemHost.</p>
  
  <p>What am I doing wrong here?</p>
  
  <pre><code>Public MustInherit Class BaseItem
      Public Property ItemNameOrSomething As String
  End Class
  
  Public Interface IItemHost(Of TItemType As {BaseItem})
      Property Items As BindingList(Of TItemType) '-- No Out parameter allowed :(
  End Interface
  
  Public Class BaseGroup(Of TGroup AS {BaseItem})
      Inherits BaseItem
      Implements IItemHost(Of TGroup)
  
      '-- This is the key property, all BaseGroup implimentors need an Items property of their specific type
      Public Property Items As New BindingList(Of TGroup)() Implements IItemHost(Of TGroup).Items
  
  End Class
  
  Public Class SpecialItem
      Inherits BaseGroup(Of ExtraSpecialItem)
  
  End Class
  
  Public Class ExtraSpecialItem
      Inherits BaseGroup(Of LeafItem)
  
  End Class
  
  Public Class LeafItem
      Inherits BaseItem
  
  End Class
  </code></pre>
  
  <p>For the most part, this all actually works. What I cannot do is:</p>
  
  <pre><code>Dim root = New SpecialItem()
  root.ItemNameOrSomething = "Testing 1"
  root.Items.Add(New ExtraSpecialItem() With {.ItemNameOrSomething = "Testing 2"})
  
  '-- This specifically, no casting options available.
  Dim item = CType(root, IItemHost(Of BaseItem))
  Dim subItems = item.Items
  Dim testing2Text = subItems.First().ItemNameOrSomething '-- = "Testing 2"
  </code></pre>