ConfigManager.cs 684 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Collections.Generic;
  2. using System.ComponentModel;
  3. using System.IO;
  4. using Helper;
  5. namespace World
  6. {
  7. public class ConfigManager<T> : ISupportInitialize, IConfigInitialize where T : IType
  8. {
  9. protected readonly Dictionary<int, T> dict = new Dictionary<int, T>();
  10. public T this[int type]
  11. {
  12. get
  13. {
  14. return dict[type];
  15. }
  16. }
  17. public Dictionary<int, T> GetAll()
  18. {
  19. return this.dict;
  20. }
  21. public void Init(string dir)
  22. {
  23. foreach (var file in Directory.GetFiles(dir))
  24. {
  25. var t = MongoHelper.FromJson<T>(File.ReadAllText(file));
  26. this.dict.Add(t.Type, t);
  27. }
  28. }
  29. public void BeginInit()
  30. {
  31. }
  32. public void EndInit()
  33. {
  34. }
  35. }
  36. }