I've looked around and haven't found anything quite matching my problem, though this is certainly close. Basically, I have a KeyedCollection of Page objects as a base, and I want strongly typed collections of derived objects to come from it. Specifically, I have:
public class Page
public class Category : Page
public class PageList<T> : KeyedCollection<string, T> where T : Page
public class CategoryList : PageList<Category>
Now, this seems fine up until I want to call a method from within the PageList<T>
using something like DoSomethingTo(this)
which is currently declared as DoSomethingTo(PageList<Page> pageList)
. This gives me a casting error.
What I'd like to be able to do, as you've probably already figured out is to use DoSomething(this)
from within either the PageList<T>
class or within the CategoryList class.
How do I make this work...or do I? I tried similar methods to what was suggested in the question I linked above, but I couldn't get anything to work. Thanks!