Exemplo n.º 1
0
        /// <summary>
        /// 注册JSON数据表
        /// </summary>
        /// <param name="name"></param>
        /// <param name="xmlStr"></param>
        public void RegisterJSONTable(string name, string jsonStr)
        {
            if (_jsonStructFolder == null)
            {
                App.logManager.Error("TableManager.RegisterJSONTable Error:JSONStructFolder has not set!");
                return;
            }

            // 判断原型字典中是否存在该数据原型
            IJSONTable jsonTable = GetJSONTablePrototype(name);

            if (jsonTable == null)
            {
                jsonTable = (IJSONTable)ReflectionHelper.CreateInstance(_jsonStructFolder + name);
            }
            if (jsonTable == null)
            {
                return;
            }
            _jsonTablePrototypeDict[name] = jsonTable;

            // 获取数据表字典
            Dictionary <int, IJSONTable> dict;

            if (_jsonTableDict.TryGetValue(name, out dict) == false)
            {
                dict = _jsonTableDict[name] = new Dictionary <int, IJSONTable>();
            }

            // 根据原型生成新数据并填充数据
            jsonTable = jsonTable.ClonePrototype();
            dict[jsonTable.FillData(jsonStr)] = jsonTable;
            jsonTable.InitData();
        }
Exemplo n.º 2
0
        /// <summary>
        /// 根据表名、ID获取JSON数据表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="name"></param>
        /// <param name="ID"></param>
        /// <returns></returns>
        public T GetJSONTable <T>(string name, int ID) where T : IJSONTable
        {
            IJSONTable table = GetJSONTable(name, ID);

            return((T)table);
        }