Парсинг командной строки
Хочу спросить у вас: как распарсить аргументы CLI в виде -xyz? То есть, мне нужно слияние команд. Пока получилось только -x -y -z. Вот код:
private static void Main(string[] parameters) {
Parser(parameters);
}
private static void Parser(string[] arguments) {
if (arguments.Length == 0) { Console.WriteLine(Help); }
else {
try {
if (arguments[0] == "name") {
int count = 1;
do {
if (Keys(arguments[count]) != "0") {
Console.WriteLine("...");
}
count++;
} while (count <= 4);
}
else if (arguments[0] == "version") { Console.WriteLine($"- {version}"); }
else { Console.WriteLine("Error."); }
}
catch (Exception x) { Console.WriteLine(x.Message); }
}
}
private static string Keys(string i) {
if (i.StartsWith('-') | i.StartsWith('/')) {
switch (Convert.ToChar(i.Substring(1))) {
case 'r':
Console.WriteLine("1");
return i;
case 'o':
Console.WriteLine("2");
return i;
case 'e':
Console.WriteLine("3");
return i;
case 'd':
Console.WriteLine("4");
return i;
default:
return "0";
}
}
return "0";
}
Пример моей команды: .\command.exe name -xyz (-x -y -z) [file_name] Заранее благодарю.
P.S. Если вы не поняли, прошу простить, я новичёк в C#.