-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
53 lines (43 loc) · 1.44 KB
/
Copy pathProgram.cs
File metadata and controls
53 lines (43 loc) · 1.44 KB
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
using ConfigLib;
using System.Net;
namespace ConfigExample
{
internal class Program
{
private static string FilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "test_config.json");
static void Main(string[] args)
{
// Start with a clean slate
Clean();
// Create a new value set
Config.Set(FilePath);
// Load / create some values
string name = Config.GetValue("name", "John Doe");
Config.SetValue("name", name);
IPAddress ip = IPAddress.Parse(Config.GetValue("ip_address", "127.0.0.1"));
Config.SetValue("ip_address", ip.ToString());
int port = int.Parse(Config.GetValue("port", "1234"));
Config.SetValue("port", port.ToString());
// List the current values
List();
// Save the values into the file
Config.Save();
}
private static void Clean()
{
if (File.Exists(FilePath))
{
File.Delete(FilePath);
}
}
private static void List()
{
Console.WriteLine("Current Values:");
foreach (KeyValuePair<string, string> item in Config.GetAllValues())
{
Console.WriteLine($"\t{item.Key} = {item.Value}");
}
Console.WriteLine();
}
}
}