using System; using System.Collections.Generic; namespace wf { public abstract class CsvCommonDatabaseIDType { public abstract string csvTopCommonName { get; } public abstract string typeNameForErrorLog { get; } public int Count { get { this.Initialize(); return this.commonIdManager.idMap.Count; } } public bool Contains(int id) { return this.commonIdManager.idMap.ContainsKey(id); } public Data GetData(int id) { this.Initialize(); NDebug.Assert(this.basicDatas.ContainsKey(id), string.Concat(new object[] { this.typeNameForErrorLog, "\nID[", id, "]のデータは存在しません" })); return this.basicDatas[id]; } public List GetAllDatas(bool onlyEnabled) { this.Initialize(); List list = new List(); foreach (KeyValuePair> keyValuePair in this.commonIdManager.idMap) { if (!onlyEnabled || this.commonIdManager.enabledIdList.Contains(keyValuePair.Key)) { list.Add(this.basicDatas[keyValuePair.Key]); } } return list; } public bool IsEnabled(int id) { this.Initialize(); return this.commonIdManager.enabledIdList.Contains(id); } public virtual bool Initialize() { if (this.commonIdManager != null) { return false; } this.commonIdManager = new CsvCommonIdManager(this.csvTopCommonName, this.typeNameForErrorLog, CsvCommonIdManager.Type.IdOnly, null); this.basicDatas = this.CreateData(this.commonIdManager); return true; } protected abstract Dictionary CreateData(CsvCommonIdManager createIds); public CsvCommonDatabaseIDType.CsvPair OpenCsvFromNameSuffix(string nameSuffix) { return this.OpenCsv(this.csvTopCommonName + "_" + nameSuffix + ".csv"); } public CsvCommonDatabaseIDType.CsvPair OpenCsv(string fileName) { bool flag; return new CsvCommonDatabaseIDType.CsvPair(fileName, ref flag); } protected CsvCommonIdManager commonIdManager; protected Dictionary basicDatas; public class CsvPair : IDisposable { public CsvPair(string fileName, out bool openResult) { this.file = GameUty.FileSystem.FileOpen(fileName); this.csv = new CsvParser(); openResult = (this.file != null && this.csv.Open(this.file)); } public CsvPair(string fileName) { this.file = GameUty.FileSystem.FileOpen(fileName); this.csv = new CsvParser(); this.csv.Open(this.file); } public CsvPair() { } ~CsvPair() { this.Dispose(); } public void Dispose() { if (this.isDisposed) { return; } this.isDisposed = true; if (this.file != null) { this.file.Dispose(); } if (this.csv != null) { this.csv.Dispose(); } this.file = null; this.csv = null; GC.SuppressFinalize(this); } public AFileBase file; public CsvParser csv; private bool isDisposed; } } }