2
This commit is contained in:
parent
92f5da95a6
commit
44f7ef01e8
@ -1,9 +1,8 @@
|
|||||||
using Stormtrooper.Drawnings;
|
using Stormtrooper.Exceptions;
|
||||||
|
using Stormtrooper.CollectionGenericObjects;
|
||||||
using Stormtrooper.Exceptions;
|
using Stormtrooper.Exceptions;
|
||||||
using System.CodeDom;
|
|
||||||
|
|
||||||
namespace Stormtrooper.CollectionGenericObjects;
|
namespace Stormtrooper.CollectionGenericObjects;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Параметризованный набор объектов
|
/// Параметризованный набор объектов
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -15,17 +14,20 @@ where T : class
|
|||||||
/// Массив объектов, которые храним
|
/// Массив объектов, которые храним
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private T?[] _collection;
|
private T?[] _collection;
|
||||||
|
|
||||||
public int Count => _collection.Length;
|
public int Count => _collection.Length;
|
||||||
|
/// <summary>
|
||||||
public int MaxCount {
|
/// Установка максимального кол-ва объектов
|
||||||
|
/// </summary>
|
||||||
|
public int MaxCount
|
||||||
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _collection.Length;
|
return _collection.Length;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value > 0) {
|
if (value > 0)
|
||||||
|
{
|
||||||
if (_collection.Length > 0)
|
if (_collection.Length > 0)
|
||||||
{
|
{
|
||||||
Array.Resize(ref _collection, value);
|
Array.Resize(ref _collection, value);
|
||||||
@ -47,6 +49,11 @@ where T : class
|
|||||||
{
|
{
|
||||||
_collection = Array.Empty<T?>();
|
_collection = Array.Empty<T?>();
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта по позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position">Позиция (индекс)</param>
|
||||||
|
/// <returns></returns>
|
||||||
public T? Get(int position)
|
public T? Get(int position)
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= _collection.Length)
|
if (position < 0 || position >= _collection.Length)
|
||||||
|
@ -54,20 +54,21 @@ where T : DrawningAircraft
|
|||||||
/// <param name="collectionType">тип коллекции</param>
|
/// <param name="collectionType">тип коллекции</param>
|
||||||
public void AddCollection(string name, CollectionType collectionType)
|
public void AddCollection(string name, CollectionType collectionType)
|
||||||
{
|
{
|
||||||
// TODO проверка, что name не пустой и нет в словаре записи с таким ключом
|
if (string.IsNullOrEmpty(name) || _storages.ContainsKey(name))
|
||||||
// TODO Прописать логику для добавления
|
return;
|
||||||
if (!(collectionType == CollectionType.None) && !_storages.ContainsKey(name))
|
switch (collectionType)
|
||||||
{
|
|
||||||
if (collectionType == CollectionType.List)
|
|
||||||
{
|
{
|
||||||
|
case CollectionType.List:
|
||||||
_storages.Add(name, new ListGenericObjects<T>());
|
_storages.Add(name, new ListGenericObjects<T>());
|
||||||
}
|
break;
|
||||||
else if (collectionType == CollectionType.Massive)
|
case CollectionType.Massive:
|
||||||
{
|
|
||||||
_storages.Add(name, new MassiveGenericObjects<T>());
|
_storages.Add(name, new MassiveGenericObjects<T>());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление коллекции
|
/// Удаление коллекции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -86,11 +87,8 @@ where T : DrawningAircraft
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
// TODO Продумать логику получения объекта
|
if (_storages.TryGetValue(name, out ICollectionGenericObjects<T>? value))
|
||||||
if (_storages.ContainsKey(name))
|
return value;
|
||||||
{
|
|
||||||
return _storages[name];
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,8 +110,6 @@ where T : DrawningAircraft
|
|||||||
File.Delete(filename);
|
File.Delete(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
using FileStream fs = new(filename, FileMode.Create);
|
using FileStream fs = new(filename, FileMode.Create);
|
||||||
using StreamWriter streamWriter = new StreamWriter(fs);
|
using StreamWriter streamWriter = new StreamWriter(fs);
|
||||||
streamWriter.Write(_collectionKey);
|
streamWriter.Write(_collectionKey);
|
||||||
|
@ -4,8 +4,8 @@ using Microsoft.Extensions.Configuration;
|
|||||||
using Serilog;
|
using Serilog;
|
||||||
using Stormtrooper;
|
using Stormtrooper;
|
||||||
|
|
||||||
namespace Battleship
|
namespace Stormtrooper;
|
||||||
{
|
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -43,4 +43,3 @@ namespace Battleship
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -9,9 +9,10 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
|
|
||||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.10" />
|
|
||||||
<PackageReference Include="Serilog" Version="3.1.1" />
|
<PackageReference Include="Serilog" Version="3.1.1" />
|
||||||
<PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
|
<PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
|
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
|
||||||
|
Loading…
Reference in New Issue
Block a user