-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDotEnv.cs
28 lines (22 loc) · 819 Bytes
/
DotEnv.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
namespace Cerberus {
public class DotEnv {
private Dictionary<string, string> variables = new Dictionary<string, string>();
public DotEnv() {
if (!File.Exists("./.env")) {
return;
}
foreach (string line in File.ReadAllLines("./.env")) {
string[] split = line.Split("=");
if (split.Length > 2) throw new Exception("Environment vars formatted incorrectly.. ?");
variables.Add(split[0], split[1]);
}
}
public string Get(string key) {
string value;
if (!variables.TryGetValue(key, out value)) {
throw new Exception(String.Format("variable with key {0} not found!", key));
}
return value;
}
}
}