2024-03-28 09:57:08 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace ProjectElectricLocomotive.CollectionGenericObjects;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Класс-хранилище коллекций
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
public class StorageCollection<T>
|
|
|
|
|
where T : class
|
|
|
|
|
{
|
2024-04-01 17:28:49 +04:00
|
|
|
|
|
2024-03-28 09:57:08 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Словарь (хранилище) с коллекциями
|
|
|
|
|
/// </summary>
|
|
|
|
|
readonly Dictionary<string, ICollectionGenericObjects<T>> _storages;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращение списка названий коллекций
|
|
|
|
|
/// </summary>
|
|
|
|
|
public List<string> Keys => _storages.Keys.ToList();
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
public StorageCollection()
|
|
|
|
|
{
|
|
|
|
|
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавление коллекции в хранилище
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">Название коллекции</param>
|
|
|
|
|
/// <param name="collectionType">тип коллекции</param>
|
|
|
|
|
public void AddCollection(string name, CollectionType collectionType)
|
|
|
|
|
{
|
2024-04-01 17:28:49 +04:00
|
|
|
|
if(collectionType != CollectionType.None && !_storages.ContainsKey(name)) {
|
|
|
|
|
if(collectionType == CollectionType.List)
|
|
|
|
|
{
|
|
|
|
|
_storages.Add(name, new ListGenericObjects<T>());
|
|
|
|
|
}
|
|
|
|
|
else if (collectionType == CollectionType.Massive)
|
|
|
|
|
{
|
|
|
|
|
_storages.Add(name, new MassiveGenericObjects<T>());
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-28 09:57:08 +04:00
|
|
|
|
// TODO проверка, что name не пустой и нет в словаре записи с таким ключом
|
|
|
|
|
// TODO Прописать логику для добавления
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удаление коллекции
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">Название коллекции</param>
|
|
|
|
|
public void DelCollection(string name)
|
|
|
|
|
{
|
2024-04-01 17:28:49 +04:00
|
|
|
|
if (_storages.ContainsKey(name))
|
|
|
|
|
{
|
|
|
|
|
_storages.Remove(name);
|
|
|
|
|
}
|
2024-03-28 09:57:08 +04:00
|
|
|
|
// TODO Прописать логику для удаления коллекции
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Доступ к коллекции
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">Название коллекции</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public ICollectionGenericObjects<T>? this[string name]
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2024-04-01 17:28:49 +04:00
|
|
|
|
if (_storages.ContainsKey(name))
|
|
|
|
|
{
|
|
|
|
|
return _storages[name];
|
|
|
|
|
}
|
2024-03-28 09:57:08 +04:00
|
|
|
|
// TODO Продумать логику получения объекта
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-01 17:28:49 +04:00
|
|
|
|
|
2024-03-28 09:57:08 +04:00
|
|
|
|
}
|