-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathProgram_CLI.cs
65 lines (58 loc) · 2.04 KB
/
Program_CLI.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
53
54
55
56
57
58
59
60
61
62
63
64
65
namespace SecureDNSClient;
internal static partial class Program
{
public readonly struct Key
{
public static readonly string IsPortable = "IsPortable";
public static readonly string IsStartup = "IsStartup";
public static readonly string StartupDelaySec = "StartupDelaySec";
}
public class KeyValue
{
public KeyValue() { }
public string Key { get; set; } = string.Empty;
public string Value { get; set; } = string.Empty;
public bool ValueBool { get; set; } = false;
public int ValueInt { get; set; } = 0;
public Type Type { get; set; } = typeof(object);
}
private static KeyValue GetValue(string arg) // arg e.g. -IsStartup=True
{
KeyValue keyValue = new();
try
{
arg = arg[1..];
char separator = '=';
if (arg.Contains(separator))
{
string[] split = arg.Split(separator);
if (split.Length == 2)
{
string argKey = split[0];
string argValue = split[1];
if (!string.IsNullOrEmpty(argKey) && !string.IsNullOrEmpty(argValue))
{
keyValue.Key = argKey;
keyValue.Value = argValue;
// Bool
bool isOk = bool.TryParse(keyValue.Value, out bool outBool);
if (isOk)
{
keyValue.ValueBool = outBool;
keyValue.Type = typeof(bool);
}
// Int
isOk = int.TryParse(keyValue.Value, out int outInt);
if (isOk)
{
keyValue.ValueInt = outInt;
keyValue.Type = typeof(int);
}
}
}
}
}
catch (Exception) { }
return keyValue;
}
}