| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using Common.Helper;
- namespace Model
- {
- public abstract class ACategory<T>: ICategory where T : AConfig
- {
- private Dictionary<int, T> dict;
- public virtual void BeginInit()
- {
- this.dict = new Dictionary<int, T>();
- string path = Path.Combine(@"../../Config/", typeof (T).Name);
- if (!Directory.Exists(path))
- {
- throw new Exception(string.Format("not found config path: {0}", path));
- }
- foreach (string file in Directory.GetFiles(path))
- {
- T t = MongoHelper.FromJson<T>(File.ReadAllText(file));
- this.dict.Add(t.Id, t);
- }
- }
- public Type ConfigType
- {
- get
- {
- return typeof (T);
- }
- }
- public virtual void EndInit()
- {
- }
- public T this[int type]
- {
- get
- {
- return this.dict[type];
- }
- }
- public T[] GetAll()
- {
- return this.dict.Values.ToArray();
- }
- }
- }
|