-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppConfig.cs
More file actions
48 lines (39 loc) · 1.27 KB
/
Copy pathAppConfig.cs
File metadata and controls
48 lines (39 loc) · 1.27 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
namespace fetcher_tester
{
public static class AppConfig
{
// pseudo-readonly configuration singleton, for simplicity
public static IConfiguration? Configuration { get; private set; }
public static bool SetConfiguration(IConfiguration configuration)
{
if (Configuration == null)
{
Configuration = configuration;
return true;
}
return false;
}
public static string? GetConfigValue(string key)
{
return Configuration?[key];
}
public static int GetConfigValue(string key, int @default = 0)
{
if (int.TryParse(Configuration?[key], out int p))
return p;
return @default;
}
public static double GetConfigValue(string key, double @default = 0.0d)
{
if (double.TryParse(Configuration?[key], out double p))
return p;
return @default;
}
public static bool GetConfigValue(string key, bool @default = false)
{
if (bool.TryParse(Configuration?[key], out bool p))
return p;
return @default;
}
}
}