public IIntervalCollection <TKey, TValue> GetIntervalCollection <TKey, TValue>(string name, Mode mode) where TKey : IComparable <TKey> { if (!_collectionsByName.TryGetValue(name, out var collection)) { ThrowIfCannotCreate(name, mode); ThrowIfNotRegistered <TKey>(); ThrowIfNotRegistered <TValue>(); IntervalCollection <TKey, TValue> .ThrowIfInvalidKey(); var tableName = AddTable(name, CollectionType.IntervalCollection, typeof(TKey), typeof(TValue)); collection = CreateIntervalCollection <TKey, TValue>(name, tableName); AddCollection(name, collection); } else { ThrowIfMustCreate(mode); } EnsureTypeSafety(collection, CollectionType.IntervalCollection, typeof(TKey), typeof(TValue)); if (!(collection is IIntervalCollection <TKey, TValue> target)) { throw new ArgumentException(string.Format("The dictionary '{0}' has a value type of '{1}': If your intent was to create a new dictionary, you have to pick a new name!", name, collection.ValueType.FullName)); } return(target); }