Untitled
unknown
plain_text
3 years ago
1.0 kB
5
Indexable
public class Config { public string TwitchClientId { get; } public string TwitchClientSecret { get; } public Config(string twitchClientId, string twitchClientSecret) { TwitchClientId = twitchClientId ?? throw new ArgumentNullException(nameof(twitchClientId)); TwitchClientSecret = twitchClientSecret ?? throw new ArgumentNullException(nameof(twitchClientSecret)); } public static Config FromFile(string path) { if (!File.Exists(path)) throw new ArgumentException($"Config file cannot be found at path '{path}'."); var content = File.ReadAllText(path); return FromJson(content); } public static Config FromJson(string json) { var config = JsonConvert.DeserializeObject<Config>(json); if (config == null) throw new ArgumentException($"Argument 'json' has an invalid value: '{json}'."); return config; } } Config config = Config.FromFile("C:/path/to/file.json");
Editor is loading...