Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using System.IO;
- namespace AuroraFramework.Configuration
- {
- public abstract class BaseConfiguration
- {
- private readonly string filePath;
- private JObject jsonSettings;
- protected BaseConfiguration(string filePath)
- {
- this.filePath = filePath;
- ReadFile();
- }
- private void ReadFile()
- {
- StreamReader reader = new StreamReader(filePath);
- jsonSettings = JsonConvert.DeserializeObject<JObject>(reader.ReadToEnd());
- }
- protected T Get<T>(string key)
- {
- return jsonSettings[key].Value<T>();
- }
- }
- }
- namespace AuroraFramework.Configuration.Types
- {
- public class DatabaseConfiguration : BaseConfiguration
- {
- public string Server { get; set; }
- public string Username { get; set; }
- public string Password { get; set; }
- public string Database { get; set; }
- public DatabaseConfiguration()
- : base("db.settings.json")
- {
- Server = Get<string>("server");
- Username = Get<string>("username");
- Password = Get<string>("password");
- Database = Get<string>("database");
- }
- }
- }
Add Comment
Please, Sign In to add comment