-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigHelper.cs
37 lines (33 loc) · 1.04 KB
/
ConfigHelper.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
using Newtonsoft.Json;
using System;
using System.IO;
using System.Windows.Forms;
namespace BatchAirdropClaim
{
public static class ConfigHelper
{
public static AppSettings LoadAppSettings()
{
try
{
var configFilePath = "appsettings.json";
if (!File.Exists(configFilePath))
{
throw new FileNotFoundException("appsettings.json file not found.");
}
var configJson = File.ReadAllText(configFilePath);
var appSettings = JsonConvert.DeserializeObject<AppSettings>(configJson);
if (appSettings == null)
{
throw new Exception("Failed to deserialize appSettings.");
}
return appSettings;
}
catch (Exception ex)
{
MessageBox.Show($"Error in LoadAppSettings: {ex.Message}");
return null;
}
}
}
}