diff --git a/src/Luban.Job.Cfg/Source/DataSources/Excel/ExcelDataSource.cs b/src/Luban.Job.Cfg/Source/DataSources/Excel/ExcelDataSource.cs index 62fd9ee..c7901f6 100644 --- a/src/Luban.Job.Cfg/Source/DataSources/Excel/ExcelDataSource.cs +++ b/src/Luban.Job.Cfg/Source/DataSources/Excel/ExcelDataSource.cs @@ -85,13 +85,6 @@ namespace Luban.Job.Cfg.DataSources.Excel public override Record ReadOne(TBean type) { - //var datas = ReadMulti(type); - //switch (datas.Count) - //{ - // case 1: return datas[0]; - // case 0: throw new Exception($"单例表不能为空,必须包含且只包含1个记录"); - // default: throw new Exception($"单例表必须恰好包含1个记录. 但当前记录数为:{datas.Count}"); - //} throw new Exception($"excel不支持单例读取模式"); } } diff --git a/src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs b/src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs index c971d77..5833c9c 100644 --- a/src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs +++ b/src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs @@ -341,18 +341,11 @@ namespace Luban.Job.Cfg.Defs switch (attrName) { case "index": - { - cf.Index = attrValue; - break; - } case "ref": case "path": case "range": { cf.Type = cf.Type + "&" + attrs[i]; - //var validator = new Validator() { Type = attrName, Rule = attrValue }; - //cf.Validators.Add(validator); - //cf.ValueValidators.Add(validator); break; } case "group": @@ -568,7 +561,6 @@ namespace Luban.Job.Cfg.Defs { new CfgField() { Name = "name", Type = "string" }, new CfgField() { Name = "type", Type = "string" }, - new CfgField() { Name = "index", Type = "string" }, new CfgField() { Name = "group", Type = "string" }, new CfgField() { Name = "comment", Type = "string" }, new CfgField() { Name = "tags", Type = "string" }, @@ -647,7 +639,6 @@ namespace Luban.Job.Cfg.Defs file.ActualFile, (b.GetField("name") as DString).Value.Trim(), (b.GetField("type") as DString).Value.Trim(), - (b.GetField("index") as DString).Value.Trim(), (b.GetField("group") as DString).Value, (b.GetField("comment") as DString).Value.Trim(), (b.GetField("tags") as DString).Value.Trim(), @@ -667,7 +658,6 @@ namespace Luban.Job.Cfg.Defs private static readonly List _fieldOptionalAttrs = new() { - "index", "ref", "path", "group", @@ -695,7 +685,6 @@ namespace Luban.Job.Cfg.Defs return CreateField(defineFile, XmlUtil.GetRequiredAttribute(e, "name"), typeStr, - XmlUtil.GetOptionalAttribute(e, "index"), XmlUtil.GetOptionalAttribute(e, "group"), XmlUtil.GetOptionalAttribute(e, "comment"), XmlUtil.GetOptionalAttribute(e, "tags"), @@ -703,14 +692,13 @@ namespace Luban.Job.Cfg.Defs ); } - private Field CreateField(string defileFile, string name, string type, string index, string group, + private Field CreateField(string defileFile, string name, string type, string group, string comment, string tags, bool ignoreNameValidation) { var f = new CfgField() { Name = name, - Index = index, Groups = CreateGroups(group), Comment = comment, Tags = tags, diff --git a/src/Luban.Job.Cfg/Source/Defs/DefField.cs b/src/Luban.Job.Cfg/Source/Defs/DefField.cs index ec15ba0..95ddfba 100644 --- a/src/Luban.Job.Cfg/Source/Defs/DefField.cs +++ b/src/Luban.Job.Cfg/Source/Defs/DefField.cs @@ -16,7 +16,7 @@ namespace Luban.Job.Cfg.Defs { public DefAssembly Assembly => (DefAssembly)HostType.AssemblyBase; - public string Index { get; } + public string Index { get; private set; } public List Groups { get; } @@ -125,7 +125,6 @@ namespace Luban.Job.Cfg.Defs public DefField(DefTypeBase host, CfgField f, int idOffset) : base(host, f, idOffset) { - Index = f.Index; this.Groups = f.Groups; this.RawDefine = f; } @@ -220,7 +219,7 @@ namespace Luban.Job.Cfg.Defs { if (CType.Tags.TryGetValue("ref", out string refStr2)) { - this.Validators.Add( this.Ref = (RefValidator)ValidatorFactory.Create("ref", refStr2)); + this.Validators.Add(this.Ref = (RefValidator)ValidatorFactory.Create("ref", refStr2)); } if (CType.Tags.TryGetValue("path", out string pathStr2)) @@ -278,28 +277,6 @@ namespace Luban.Job.Cfg.Defs break; } } - - if (!string.IsNullOrEmpty(Index)) - { - if ((CType is TArray tarray) && (tarray.ElementType is TBean b)) - { - if ((IndexField = b.GetBeanAs().GetField(Index)) == null) - { - throw new Exception($"type:'{HostType.FullName}' field:'{Name}' index:'{Index}'. index not exist"); - } - } - else if ((CType is TList tlist) && (tlist.ElementType is TBean tb)) - { - if ((IndexField = tb.GetBeanAs().GetField(Index)) == null) - { - throw new Exception($"type:'{HostType.FullName}' field:'{Name}' index:'{Index}'. index not exist"); - } - } - else - { - throw new Exception($"type:'{HostType.FullName}' field:'{Name}' index:'{Index}'. only array:bean or list:bean support index"); - } - } } private void ValidateRef(RefValidator val, TType refVarType) @@ -370,6 +347,30 @@ namespace Luban.Job.Cfg.Defs } } } + + Index = CType.GetTag("index"); + + if (!string.IsNullOrEmpty(Index)) + { + if ((CType is TArray tarray) && (tarray.ElementType is TBean b)) + { + if ((IndexField = b.GetBeanAs().GetField(Index)) == null) + { + throw new Exception($"type:'{HostType.FullName}' field:'{Name}' index:'{Index}'. index not exist"); + } + } + else if ((CType is TList tlist) && (tlist.ElementType is TBean tb)) + { + if ((IndexField = tb.GetBeanAs().GetField(Index)) == null) + { + throw new Exception($"type:'{HostType.FullName}' field:'{Name}' index:'{Index}'. index not exist"); + } + } + else + { + throw new Exception($"type:'{HostType.FullName}' field:'{Name}' index:'{Index}'. only array:bean or list:bean support index"); + } + } } } } diff --git a/src/Luban.Job.Cfg/Source/RawDefs/CfgField.cs b/src/Luban.Job.Cfg/Source/RawDefs/CfgField.cs index d2e2ae1..f55e9bd 100644 --- a/src/Luban.Job.Cfg/Source/RawDefs/CfgField.cs +++ b/src/Luban.Job.Cfg/Source/RawDefs/CfgField.cs @@ -5,8 +5,6 @@ namespace Luban.Job.Cfg.RawDefs { public class CfgField : Field { - public string Index { get; set; } - public List Groups { get; set; } = new List(); } } diff --git a/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs b/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs index b8c0e95..75adab0 100644 --- a/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs +++ b/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs @@ -124,8 +124,9 @@ namespace Luban.Job.Common.Defs #endif if (sepIndex > 0) { - string containerType = type.Substring(0, sepIndex).Trim(); - return CreateContainerType(module, containerType, type.Substring(sepIndex + 1, type.Length - sepIndex - 1).Trim()); + var (containerAndElementType, tags) = DefUtil.ParseType(type); + string containerType = containerAndElementType.Substring(0, sepIndex).Trim(); + return CreateContainerType(module, containerType, tags, containerAndElementType.Substring(sepIndex + 1, containerAndElementType.Length - sepIndex - 1).Trim()); } else { @@ -203,30 +204,30 @@ namespace Luban.Job.Common.Defs } } - protected TMap CreateMapType(string module, string keyValueType, bool isTreeMap) + protected TMap CreateMapType(string module, Dictionary tags, string keyValueType, bool isTreeMap) { string[] elementTypes = keyValueType.Split(',').Select(s => s.Trim()).ToArray(); if (elementTypes.Length != 2) { throw new ArgumentException($"invalid map element type:'{keyValueType}'"); } - return TMap.Create(false, null, CreateNotContainerType(module, elementTypes[0]), CreateNotContainerType(module, elementTypes[1]), isTreeMap); + return TMap.Create(false, tags, CreateNotContainerType(module, elementTypes[0]), CreateNotContainerType(module, elementTypes[1]), isTreeMap); } - protected TType CreateContainerType(string module, string containerType, string elementType) + protected TType CreateContainerType(string module, string containerType, Dictionary containerTags, string elementType) { switch (containerType) { - case "array": return TArray.Create(false, new Dictionary(), CreateNotContainerType(module, elementType)); - case "list": return TList.Create(false, new Dictionary(), CreateNotContainerType(module, elementType), true); - case "linkedlist": return TList.Create(false, new Dictionary(), CreateNotContainerType(module, elementType), false); - case "arraylist": return TList.Create(false, new Dictionary(), CreateNotContainerType(module, elementType), true); - case "set": return TSet.Create(false, new Dictionary(), CreateNotContainerType(module, elementType), false); - case "hashset": return TSet.Create(false, new Dictionary(), CreateNotContainerType(module, elementType), false); - case "treeset": return TSet.Create(false, new Dictionary(), CreateNotContainerType(module, elementType), true); - case "map": return CreateMapType(module, elementType, false); - case "treemap": return CreateMapType(module, elementType, true); - case "hashmap": return CreateMapType(module, elementType, false); + case "array": return TArray.Create(false, containerTags, CreateNotContainerType(module, elementType)); + case "list": return TList.Create(false, containerTags, CreateNotContainerType(module, elementType), true); + case "linkedlist": return TList.Create(false, containerTags, CreateNotContainerType(module, elementType), false); + case "arraylist": return TList.Create(false, containerTags, CreateNotContainerType(module, elementType), true); + case "set": return TSet.Create(false, containerTags, CreateNotContainerType(module, elementType), false); + case "hashset": return TSet.Create(false, containerTags, CreateNotContainerType(module, elementType), false); + case "treeset": return TSet.Create(false, containerTags, CreateNotContainerType(module, elementType), true); + case "map": return CreateMapType(module, containerTags, elementType, false); + case "treemap": return CreateMapType(module, containerTags, elementType, true); + case "hashmap": return CreateMapType(module, containerTags, elementType, false); default: { throw new ArgumentException($"invalid container type. module:'{module}' container:'{containerType}' element:'{elementType}'");