This commit is contained in:
Александр Бабаев 2023-04-09 10:56:43 +03:00
parent 4a8e1a987b
commit 455e88635a
2 changed files with 64 additions and 3 deletions

View File

@ -0,0 +1,61 @@
namespace anbs_cp.Classes;
/// <summary>
/// Обработчик параметров консоли
/// </summary>
public sealed class ConsoleParamsParser
{
/// <summary>
/// Массив параметров
/// </summary>
private readonly List<(string, string?)> _paramsList;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="consoleParams">Параметры консоли</param>
public ConsoleParamsParser (string[] consoleParams)
{
//Создаю список параметров
_paramsList = new();
//Заполняю его
foreach (string consoleParam in consoleParams)
{
//Индекс знака "="
int eqPlace = consoleParam.IndexOf('=');
//Получаю параметр
string param = eqPlace > -1 ? consoleParam[..eqPlace] : consoleParam;
//Получаю значение параметра
string? value = eqPlace == -1 ? null : consoleParam[(eqPlace + 1)..].Trim(new[] { '"' });
//Сохраняю в списке
_paramsList.Add((param, value));
}
}
/// <summary>
/// Проверяет наличие параметра
/// </summary>
/// <param name="param">Параметр</param>
/// <returns>Есть ли параметр в списке</returns>
public bool HasParam (string param) =>
_paramsList.Any(keyValue => keyValue.Item1 == param);
/// <summary>
/// Получает значение параметра
/// </summary>
/// <param name="param"></param>
/// <returns></returns>
public string? GetValue (string param) =>
!HasParam(param) ? null : _paramsList.FirstOrDefault(keyValue => keyValue.Item1 == param).Item2;
/// <summary>
/// Получает список всех параметров
/// </summary>
/// <returns>Список всех параметров</returns>
public List<string> GetParamsList () =>
_paramsList.Select(static keyValue => keyValue.Item1).ToList();
}

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net7.0</TargetFramework> <TargetFramework>net7.0</TargetFramework>
<Version>2023.212.0</Version> <Version>2023.409.0</Version>
<Authors>Alexander Babaev</Authors> <Authors>Alexander Babaev</Authors>
<Product>ANB Software Components Pack</Product> <Product>ANB Software Components Pack</Product>
<Description>Library of some useful functions in C# language.</Description> <Description>Library of some useful functions in C# language.</Description>
@ -40,9 +40,9 @@
<PackageReference Include="gfoidl.Base64" Version="2.0.0" /> <PackageReference Include="gfoidl.Base64" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Html.Abstractions" Version="2.2.0" /> <PackageReference Include="Microsoft.AspNetCore.Html.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="5.0.17" /> <PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="5.0.17" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop" Version="17.4.33103.184" /> <PackageReference Include="Microsoft.VisualStudio.Shell.Interop" Version="17.5.33428.366" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="7.0.0" /> <PackageReference Include="Microsoft.Windows.Compatibility" Version="7.0.0" />
<PackageReference Include="MimeTypes" Version="2.4.0"> <PackageReference Include="MimeTypes" Version="2.4.1">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>