From 4f1193248dd9caabca278479ff3bdc30f5ed9632 Mon Sep 17 00:00:00 2001 From: azw Date: Sat, 18 May 2024 20:45:45 +0800 Subject: [PATCH] 1 --- F6/MetaTable.cs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/F6/MetaTable.cs b/F6/MetaTable.cs index 8921d8e..0311a35 100644 --- a/F6/MetaTable.cs +++ b/F6/MetaTable.cs @@ -10,6 +10,7 @@ using Newtonsoft; namespace F6 { + public delegate bool TraverseCb(T ele); public interface IMetaTable @@ -87,7 +88,7 @@ namespace F6 { this.fileName = fileName; this.primKey = primKey; - } + } public void Traverse(TraverseCb cb) { @@ -104,7 +105,6 @@ namespace F6 { if (this.rawList.Count > 0) { - return this.rawList[new Random().Next(0, this.rawList.Count)]; } return default(T); @@ -114,11 +114,34 @@ namespace F6 { try { + BaseMeta baseMeta = new BaseMeta(); + { + Type tType = typeof(T); + Type tBaseType = tType.BaseType; + int fieldIdx = 0; + foreach(var f in tBaseType.GetFields()) + { + string fieldName = f.Name; + var tAttrs = f.GetCustomAttributes(typeof(MetaTableFieldAttribute), false); + if (tAttrs.Length > 0) + { + var tAttr = (MetaTableFieldAttribute)tAttrs.First(); + if (tAttr != null) + { + fieldName = tAttr.fieldName; + } + } + baseMeta.nameIdxHash.Add(f.Name, fieldIdx); + baseMeta.nameIdxHash.Add(fieldName, fieldIdx); + ++fieldIdx; + } + } string fileContent = File.ReadAllText(this.fileName); var dataSet = Newtonsoft.Json.JsonConvert.DeserializeObject>>(fileContent); foreach(var row in dataSet) { T t = new T(); + t._meta = baseMeta; Type tType = typeof(T); Type tBaseType = tType.BaseType; int fieldIdx = 0;