// 读取指定名字的表, 可根据实际需求调整该函数适应不同加载数据来源 static void LoadTableByName(main.Table tab, string tableName) { using (var stream = new FileStream(string.Format("../../../../binary/{0}.bin", tableName), FileMode.Open)) { stream.Position = 0; var reader = new tabtoy.TableReader(stream); try { tab.Deserialize(reader); } catch (Exception e) { Console.WriteLine(e); throw; } } tab.IndexData(tableName); }
// 加载所有表 static void LoadAllTable() { using (var stream = new FileStream("../../../../binary/table_gen.bin", FileMode.Open)) { stream.Position = 0; var reader = new tabtoy.TableReader(stream); var tab = new main.Table(); try { tab.Deserialize(reader); } catch (Exception e) { Console.WriteLine(e); throw; } // 建立所有数据的索引 tab.IndexData(); // 表遍历 foreach (var kv in tab.ExampleData) { Console.Write("{0} {1}\n", kv.ID, kv.Name); } // 直接取值 Console.WriteLine(tab.ExtendData[1].Additive); // KV配置 Console.WriteLine(tab.GetKeyValue_ExampleKV().ServerIP); } }