I have the following class hierarchy.
class Header { IEnumerable<Item> Item { get; set; } .... }
class HeaderA : Header { .... } // Item should have the type of IEnumerable<ItemA>
class HeaderB : Header { .... } // Item should have the type of IEnumerable<ItemB>
class Item { .... }
class ItemA : Item { .... }
class ItemB : Item { .... }
Is it possible to have compile time checking on the type of Item to make sure it’s IEnumerable<ItemA>, IEnumerable<ItemB> for ItemA and ItemB respectively? Is there any better design?
You can change the definition of the Header class to pass the type parameter to it, then you could impose that: