Here’s the situation:
There’s a base class of type BaseObject ,from which all other classes are derived(i.e. Task : BaseObject).
There’s also a base class collection of type BaseObjectCollection which inherits from Dictionary<ulong,BaseObject> and some other collections that inherit from it (i.e. TaskCollection:BaseObjectCollection).
When iterating over TaskCollection members they are shown as BaseObject type.
Is there any way to make the collection “change” its values’ types so that it will possess the functionality of BaseobjectCollection and yet appear as Dictionary<ulong,Task> instead of Dictionary<ulong,BaseObject>
Here’s the situation: There’s a base class of type BaseObject ,from which all other
Share
You should change your
BaseObjectCollectiontype to be generic in the type of value it will use. For example:Then you can use a
BaseObjectCollection<Task>and still be completely type-safe.(I would personally use composition in most cases rather than deriving a new type from
Dictionary<,>but that’s a different matter.)