I need your help for an issue about inheritance. In a project of mine I am using a the SyndicationFeed .net class to read several feed a make a ul of its elements. For every element I want to show the feed's image as well, so I wanted to assign the same ImageUrl property of the feed to the single item. So I started by creating a derived class:
Public Class SyndicationItemWImage
Inherits SyndicationItem
Private mItemImage As Uri
Public Property ItemImage As Uri
Get
Return mItemImage
End Get
Set(value As Uri)
mItemImage = value
End Set
End Property
End Class
Then I would initialize the object and populate it
Dim BlogsPostsWImage As List(Of SyndicationItemWImage)
BlogsPostsWImage = New List(Of SyndicationItemWImage)
…
[initialize SyndFeed]
…
BlogsPostsWImage.AddRange(SyndFeed.Items.ToList.GetRange(0, 10))
Where SynFeed is a well working SyndicationFeed object. Unfortunately I get an error that the cast is invalid:
System.InvalidCastException: Unable to cast object of type 'System.Collections.Generic.List
1[System.ServiceModel.Syndication.SyndicationItem]' to type 'System.Collections.Generic.IEnumerable
1[lucamauricom.SyndicationItemWImage]'. at lucamauricom._default.Page_Load(Object sender, EventArgs e)
I do not understand why: shouldn't the cast from a parent class to a child one be allowed? I think I am missing something fundamental here… not sure what.
Thanks for any help you can provide.