예제 #1
0
        /// <summary>
        /// 真正进行读取
        /// </summary>
        /// <param name="type"></param>
        /// <param name="contents"></param>
        private void DoLoadTab(Type type, IEnumerable <string> contents)
        {
            Debuger.Assert(typeof(CBaseInfo).IsAssignableFrom(type));
            foreach (string content in contents)
            {
                using (KTabFile tabFile = KTabFile.LoadFromString(content))
                {
                    Dictionary <string, CBaseInfo> dict;
                    if (!SettingInfos.TryGetValue(type, out dict)) // 如果没有才添加
                    {
                        dict = new Dictionary <string, CBaseInfo>();
                    }

                    const int rowStart = 1;
                    for (int row = rowStart; row <= tabFile.GetHeight(); row++)
                    {
                        // 先读取ID, 获取是否之前已经读取过配置,
                        // 如果已经读取过,那么获取原配置对象,并重新赋值 (因为游戏中其它地方已经存在它的引用了,直接替换内存泄露)
                        string    id = tabFile.GetString(row, "Id"); // 获取ID是否存在, 如果已经存在,那么替换其属性,不new一个
                        CBaseInfo existOne;
                        if (dict.TryGetValue(id, out existOne))
                        {
                            if (FoundDuplicatedIdEvent != null)
                            {
                                FoundDuplicatedIdEvent(type, row, id);
                            }

                            CBaseInfo existInfo = existOne;
                            existInfo.ReadFromTab(type, ref existInfo, tabFile, row); // 修改原对象,不new
                            existInfo.CustomReadLine(tabFile, row);
                            (existInfo as CBaseInfo).Parse();
                        }
                        else
                        {
                            CBaseInfo pInfo = CBaseInfo.NewFromTab(type, tabFile, row);
                            pInfo.CustomReadLine(tabFile, row);
                            pInfo.Parse();
                            dict[pInfo.Id] = pInfo; // 不存在,直接new
                        }
                    }

                    SettingInfos[type] = dict;
                }
            }
        }
예제 #2
0
 public string GetString(string colName)
 {
     return(TabFile.GetString(Row, colName));
 }