You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Zero/ZeroLevel/Services/Config/Implementation/CommandLineReader.cs

55 lines
1.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Globalization;
namespace ZeroLevel.Services.Config.Implementation
{
internal sealed class CommandLineReader
: IConfigurationReader
{
private readonly string[] _args;
public CommandLineReader(string[] args)
{
_args = args;
}
public IConfiguration ReadConfiguration()
{
var result = Configuration.Create();
if (_args != null)
{
try
{
foreach (string arg in _args)
{
int index = arg.IndexOf('=');
string key;
string value;
if (index >= 0)
{
key = arg.Substring(0, index).TrimStart('/').Trim().ToLower(CultureInfo.CurrentCulture);
value = arg.Substring(index + 1, arg.Length - index - 1).Trim(' ', '"');
}
else
{
key = arg.TrimStart('-', '/').Trim().ToLower(CultureInfo.CurrentCulture);
value = string.Empty;
}
result.Append(key, value);
}
}
catch (Exception ex)
{
throw new InvalidOperationException("Не удалось создать конфигурацию из аргументов командной строки", ex);
}
}
return result;
}
public IConfigurationSet ReadConfigurationSet()
{
return Configuration.CreateSet(ReadConfiguration());
}
}
}

Powered by TurnKey Linux.