-
Notifications
You must be signed in to change notification settings - Fork 1
/
Config.cs
46 lines (38 loc) · 1.09 KB
/
Config.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
//Thanks FrFuel for this simple Config Dict getter. <3
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LaLifeWrapper
{
public class Config
{
protected Dictionary<string, string> Entries { get; set; }
public Config(string content)
{
Entries = new Dictionary<string, string>();
if (content == null || content.Length == 0)
{
return;
}
var splitted = content
.Split('\n')
.Where((line) => !line.Trim().StartsWith("#"))
.Select((line) => line.Trim().Split('='))
.Where((line) => line.Length == 2);
foreach (var tuple in splitted)
{
Entries.Add(tuple[0], tuple[1]);
}
}
public string Get(string key, string defaultValue = null)
{
if (Entries.ContainsKey(key))
{
return Entries[key];
}
return defaultValue;
}
}
}