IConfiguration.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. namespace InABox.Configuration
  4. {
  5. public interface IConfiguration<T>
  6. {
  7. string[] Sections();
  8. T Load(bool useCache = true);
  9. Dictionary<string, T> LoadAll();
  10. void Save(T obj);
  11. /// <summary>
  12. /// Save all <paramref name="objs"/> to the configuration.
  13. /// </summary>
  14. /// <remarks>
  15. /// This does not do a complete replace; that is, it only changes the configurations with the keys of <paramref name="objs"/>,
  16. /// as if <see cref="Save(T)"/> was called for each element in <paramref name="objs"/>
  17. /// </remarks>
  18. /// <param name="objs"></param>
  19. void SaveAll(Dictionary<string, T> objs);
  20. void Delete(Action<Exception?>? callback = null);
  21. }
  22. public abstract class Configuration<T> : IConfiguration<T>
  23. {
  24. public Configuration(string section = "")
  25. {
  26. Section = section;
  27. }
  28. public string Section { get; }
  29. public abstract string[] Sections();
  30. public abstract Dictionary<string, T> LoadAll();
  31. public abstract T Load(bool useCache = true);
  32. public abstract void Save(T obj);
  33. public abstract void SaveAll(Dictionary<string, T> objs);
  34. public abstract void Delete(Action<Exception?>? callback);
  35. }
  36. public interface IConfigurationSettings
  37. {
  38. }
  39. public delegate T LoadSettings<T>(object sender) where T : IConfigurationSettings;
  40. public delegate void SaveSettings<T>(object sender, T properties) where T : IConfigurationSettings;
  41. }