PIbd-14_Pruidze_I.K_Simple_.../ProjectCruiser/CollectionGenericObj/StorageCollection.cs

52 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

namespace ProjectCruiser.CollectionGenericObj;
public class StorageCollection<T>
where T : class
{
// Словарь (хранилище) с коллекциями < name, type (class) >
readonly Dictionary<string, ICollectionGenObj<T>> _storages;
// Возвращение списка названий коллекций
public List<string> Keys => _storages.Keys.ToList();
public StorageCollection()
{
_storages = new Dictionary<string, ICollectionGenObj<T>>();
}
/// Добавление коллекции в хранилище
/// <param name="name">Название коллекции</param>
/// <param name="collectionType">тип коллекции</param>
public void AddCollection(string name, CollectionType collType)
{
if (name == null || _storages.ContainsKey(name)
|| collType == CollectionType.None)
{
return;
}
switch (collType)
{
case CollectionType.List: _storages.Add(name, new ListGenObj<T>()); break;
// _storages[name] = new ListGenericObjects<T>(); break; [*]
case CollectionType.Array: _storages.Add(name, new ArrayGenObj<T>()); break;
}
}
/// Удаление коллекции ( по ключу-строке - её имени )
/// <param name="name">Название коллекции</param>
public void DelCollection(string name)
{
if (_storages.ContainsKey(name)) _storages.Remove(name);
return;
}
/// Доступ к коллекции ( по ключу-строке - её имени )
public ICollectionGenObj<T>? this[string name]
{
get => _storages.ContainsKey(name) ? _storages[name] : null;
}
}