2024-04-25 02:02:47 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace lab1.CollectionGenericObjects;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Класс-хранилище коллекций
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
public class StorageCollection<T>
|
2024-05-23 11:15:50 +04:00
|
|
|
|
where T : class
|
2024-04-25 02:02:47 +04:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2024-05-23 11:15:50 +04:00
|
|
|
|
/// Словарь (хранилище) с коллекциями
|
2024-04-25 02:02:47 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
readonly Dictionary<string, ICollectionGenericObjects<T>> _storages;
|
2024-05-23 11:15:50 +04:00
|
|
|
|
|
2024-04-25 02:02:47 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращение списка названий коллекций
|
|
|
|
|
/// </summary>
|
|
|
|
|
public List<string> Keys => _storages.Keys.ToList();
|
2024-05-23 11:15:50 +04:00
|
|
|
|
|
2024-04-25 02:02:47 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
public StorageCollection()
|
|
|
|
|
{
|
|
|
|
|
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
|
|
|
|
|
}
|
2024-05-23 11:15:50 +04:00
|
|
|
|
|
2024-04-25 02:02:47 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавление коллекции в хранилище
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">Название коллекции</param>
|
2024-05-23 11:15:50 +04:00
|
|
|
|
/// <param name="collectionType">тип коллекции</param>
|
2024-04-25 02:02:47 +04:00
|
|
|
|
public void AddCollection(string name, CollectionType collectionType)
|
|
|
|
|
{
|
2024-05-23 11:15:50 +04:00
|
|
|
|
|
|
|
|
|
if (_storages.ContainsKey(name)) return;
|
|
|
|
|
if (collectionType == CollectionType.None) return;
|
|
|
|
|
else if (collectionType == CollectionType.Massive)
|
|
|
|
|
_storages[name] = new MassiveGenericObjects<T>();
|
|
|
|
|
else if (collectionType == CollectionType.List)
|
|
|
|
|
_storages[name] = new ListGenericObjects<T>();
|
2024-04-25 02:02:47 +04:00
|
|
|
|
}
|
2024-05-23 11:15:50 +04:00
|
|
|
|
|
2024-04-25 02:02:47 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удаление коллекции
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">Название коллекции</param>
|
|
|
|
|
public void DelCollection(string name)
|
|
|
|
|
{
|
|
|
|
|
if (_storages.ContainsKey(name))
|
|
|
|
|
_storages.Remove(name);
|
|
|
|
|
}
|
2024-05-23 11:15:50 +04:00
|
|
|
|
|
2024-04-25 02:02:47 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Доступ к коллекции
|
|
|
|
|
/// </summary>
|
2024-05-23 11:15:50 +04:00
|
|
|
|
/// <param name="name">Название коллекции</param>
|
2024-04-25 02:02:47 +04:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public ICollectionGenericObjects<T>? this[string name]
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_storages.ContainsKey(name))
|
|
|
|
|
return _storages[name];
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|