Many months later and I think I've come up with a really nice solution, which is to use a collection I wasn't aware of initially KeyedCollection
:
public class TypedSet<AbstractType> : KeyedCollection<Type, AbstractType> {
protected override Type GetKeyForItem(AbstractType item) {
return item.GetType();
}
}
Very conscice and doesn't require any stitching of different types of collection classes together. Makes for slightly more idiomatic code as well as KeyedCollection
is abstract and requires implementation of GetKeyForItem
.