Guest User

Untitled

a guest
Jun 2nd, 2018
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Linq;
  3. using System.IO;
  4.  
  5. namespace AuroraFramework.Configuration
  6. {
  7. public abstract class BaseConfiguration
  8. {
  9. private readonly string filePath;
  10. private JObject jsonSettings;
  11.  
  12. protected BaseConfiguration(string filePath)
  13. {
  14. this.filePath = filePath;
  15. ReadFile();
  16. }
  17.  
  18. private void ReadFile()
  19. {
  20. StreamReader reader = new StreamReader(filePath);
  21.  
  22. jsonSettings = JsonConvert.DeserializeObject<JObject>(reader.ReadToEnd());
  23. }
  24.  
  25. protected T Get<T>(string key)
  26. {
  27. return jsonSettings[key].Value<T>();
  28. }
  29. }
  30. }
  31.  
  32. namespace AuroraFramework.Configuration.Types
  33. {
  34. public class DatabaseConfiguration : BaseConfiguration
  35. {
  36. public string Server { get; set; }
  37. public string Username { get; set; }
  38. public string Password { get; set; }
  39. public string Database { get; set; }
  40.  
  41. public DatabaseConfiguration()
  42. : base("db.settings.json")
  43. {
  44. Server = Get<string>("server");
  45. Username = Get<string>("username");
  46. Password = Get<string>("password");
  47. Database = Get<string>("database");
  48. }
  49. }
  50. }
Add Comment
Please, Sign In to add comment