【调整】cfg bean的field字段的index属性移到type中,xml及__bean__.xlsx中不再接受单独的index定义
parent
81909562a0
commit
08720156e8
|
|
@ -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不支持单例读取模式");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<string> _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,
|
||||
|
|
|
|||
|
|
@ -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<string> 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<DefBean>().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<DefBean>().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<DefBean>().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<DefBean>().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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@ namespace Luban.Job.Cfg.RawDefs
|
|||
{
|
||||
public class CfgField : Field
|
||||
{
|
||||
public string Index { get; set; }
|
||||
|
||||
public List<string> Groups { get; set; } = new List<string>();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<string, string> 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<string, string> containerTags, string elementType)
|
||||
{
|
||||
switch (containerType)
|
||||
{
|
||||
case "array": return TArray.Create(false, new Dictionary<string, string>(), CreateNotContainerType(module, elementType));
|
||||
case "list": return TList.Create(false, new Dictionary<string, string>(), CreateNotContainerType(module, elementType), true);
|
||||
case "linkedlist": return TList.Create(false, new Dictionary<string, string>(), CreateNotContainerType(module, elementType), false);
|
||||
case "arraylist": return TList.Create(false, new Dictionary<string, string>(), CreateNotContainerType(module, elementType), true);
|
||||
case "set": return TSet.Create(false, new Dictionary<string, string>(), CreateNotContainerType(module, elementType), false);
|
||||
case "hashset": return TSet.Create(false, new Dictionary<string, string>(), CreateNotContainerType(module, elementType), false);
|
||||
case "treeset": return TSet.Create(false, new Dictionary<string, string>(), 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}'");
|
||||
|
|
|
|||
Loading…
Reference in New Issue