From 53f4a3c44d0a6a769b846dd08f5e093b80a720c8 Mon Sep 17 00:00:00 2001 From: azw Date: Sat, 18 May 2024 21:09:46 +0800 Subject: [PATCH] 1 --- F6/MetaTable.cs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/F6/MetaTable.cs b/F6/MetaTable.cs index 0311a35..bef8477 100644 --- a/F6/MetaTable.cs +++ b/F6/MetaTable.cs @@ -58,6 +58,7 @@ namespace F6 { public BaseMeta _meta; public BitArray _flags = new BitArray(100); + public string _primKeyVal; virtual public bool HasValue(string fieldName) { return this.HasValue(this.GetFieldIdx(fieldName)); @@ -132,7 +133,10 @@ namespace F6 } } baseMeta.nameIdxHash.Add(f.Name, fieldIdx); - baseMeta.nameIdxHash.Add(fieldName, fieldIdx); + if (!baseMeta.nameIdxHash.ContainsKey(fieldName)) + { + baseMeta.nameIdxHash.Add(fieldName, fieldIdx); + } ++fieldIdx; } } @@ -142,6 +146,7 @@ namespace F6 { T t = new T(); t._meta = baseMeta; + row.TryGetValue(this.primKey, out t._primKeyVal); Type tType = typeof(T); Type tBaseType = tType.BaseType; int fieldIdx = 0; @@ -198,6 +203,7 @@ namespace F6 } this.rawList.Add(t); } + this.LoadPost(); }catch(Exception e) { int i = 0; @@ -212,7 +218,7 @@ namespace F6 public class IdMetaTable: RawMetaTable where T : BaseTable, new() { - protected Dictionary idHash = new Dictionary (); + protected Dictionary idHash = new Dictionary (); public T GetById(Int64 id) { @@ -224,11 +230,22 @@ namespace F6 protected override void LoadPost() { base.LoadPost(); + long idx = 0; + this.Traverse((T ele)=> { + if (this.primKey.Equals("")) + { + this.idHash.Add(idx, ele); + } else + { + this.idHash.Add(long.Parse(ele._primKeyVal), ele); + } + ++idx; + return true; + }); } public IdMetaTable(string fileName, string primKey) :base(fileName, primKey) { - // base(fileName, primKey); } } @@ -247,6 +264,10 @@ namespace F6 protected override void LoadPost() { base.LoadPost(); + this.Traverse((T ele) => { + this.nameHash.Add(ele._primKeyVal, ele); + return true; + }); } public NameMetaTable(string fileName, string primKey):base(fileName, primKey)