This repository has been archived by the owner on Apr 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArgsParser.cs
52 lines (49 loc) · 1.58 KB
/
ArgsParser.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System.Collections.Generic;
namespace Auto_Invitation
{
public class ArgsParser
{
public static Dictionary<string, string> FromStringArray(string[] args)
{
var dic = new Dictionary<string, string>();
dic.Add("DEFAULT", "");
string _lastArg = "";
foreach (var arg in args)
{
if (_lastArg != "")
{
if (arg.StartsWith("--"))
{
if (!dic.ContainsKey(_lastArg))
dic.Add(_lastArg, "true");
else
dic[_lastArg] = dic[_lastArg] + "," + "true";
_lastArg = arg.Substring(2);
}
else
{
if (!dic.ContainsKey(_lastArg))
dic.Add(_lastArg, arg);
else
dic[_lastArg] = dic[_lastArg] + "," + arg;
_lastArg = "";
}
}
else
{
if (arg.StartsWith("--"))
{
_lastArg = arg.Substring(2);
}
else
{
dic["DEFAULT"] = dic["DEFAULT"] + "," + arg;
}
}
}
if (!dic.ContainsKey(_lastArg) && _lastArg != "")
dic.Add(_lastArg, "true");
return dic;
}
}
}