ConfigManager.cs 563 B

123456789101112131415161718192021222324252627282930313233
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using Helper;
  4. namespace Component
  5. {
  6. public class ConfigManager<T> where T : IType
  7. {
  8. private readonly Dictionary<int, T> dict = new Dictionary<int, T>();
  9. public virtual void LoadConfig(string dir)
  10. {
  11. foreach (var file in Directory.GetFiles(dir))
  12. {
  13. var t = MongoHelper.FromJson<T>(File.ReadAllText(file));
  14. this.dict.Add(t.Type, t);
  15. }
  16. }
  17. public T this[int type]
  18. {
  19. get
  20. {
  21. return dict[type];
  22. }
  23. }
  24. public Dictionary<int, T> GetAll()
  25. {
  26. return this.dict;
  27. }
  28. }
  29. }