【修复】修复enum与bean没有正确处理tags导致枚举类型字段无法正确生成ref的bug

main
walon 2021-10-28 16:20:34 +08:00
parent e54870fb02
commit 38b410f0a5
9 changed files with 82 additions and 35 deletions

View File

@ -158,7 +158,16 @@ array与list类型都能表示列表它们区别在于array生成的代码为
<tr align="center"> <tr align="center">
<td/> <td/>
<td>2</td> <td>2</td>
<td>2,4</td> <td>2;4</td>
<td>3</td><td>4</td><td>5</td><td></td>
<td>aaaa|bbbb|cccc</td>
<td>aaa</td><td>bbb</td><td>ccc</td>
</tr>
<tr align="center">
<td/>
<td>3</td>
<td>2|4|6</td>
<td>3</td><td>4</td><td>5</td><td>6</td> <td>3</td><td>4</td><td>5</td><td>6</td>
<td>aaaa|bbbb|cccc</td> <td>aaaa|bbbb|cccc</td>
<td>aaa</td><td>bbb</td><td>ccc</td> <td>aaa</td><td>bbb</td><td>ccc</td>

View File

@ -481,7 +481,7 @@ namespace Luban.Job.Cfg.DataCreators
public DType Accept(TMap type, Sheet sheet, TitleRow row) public DType Accept(TMap type, Sheet sheet, TitleRow row)
{ {
string sep = DataUtil.GetSep(type); string sep = "";
if (row.Row != null) if (row.Row != null)
{ {

View File

@ -418,7 +418,7 @@ namespace Luban.Job.Cfg.Defs
defTableRecordType.PreCompile(); defTableRecordType.PreCompile();
defTableRecordType.Compile(); defTableRecordType.Compile();
defTableRecordType.PostCompile(); defTableRecordType.PostCompile();
var tableRecordType = TBean.Create(false, defTableRecordType); var tableRecordType = TBean.Create(false, defTableRecordType, null);
foreach (var file in inputFileInfos) foreach (var file in inputFileInfos)
{ {
@ -485,7 +485,7 @@ namespace Luban.Job.Cfg.Defs
defTableRecordType.PreCompile(); defTableRecordType.PreCompile();
defTableRecordType.Compile(); defTableRecordType.Compile();
defTableRecordType.PostCompile(); defTableRecordType.PostCompile();
var tableRecordType = TBean.Create(false, defTableRecordType); var tableRecordType = TBean.Create(false, defTableRecordType, null);
foreach (var file in inputFileInfos) foreach (var file in inputFileInfos)
{ {
@ -592,7 +592,7 @@ namespace Luban.Job.Cfg.Defs
defTableRecordType.PreCompile(); defTableRecordType.PreCompile();
defTableRecordType.Compile(); defTableRecordType.Compile();
defTableRecordType.PostCompile(); defTableRecordType.PostCompile();
var tableRecordType = TBean.Create(false, defTableRecordType); var tableRecordType = TBean.Create(false, defTableRecordType, null);
foreach (var file in inputFileInfos) foreach (var file in inputFileInfos)
{ {

View File

@ -139,23 +139,15 @@ namespace Luban.Job.Cfg.Utils
return tags.Count > 0 ? tags : null; return tags.Count > 0 ? tags : null;
} }
public const string SimpleContainerSep = ",;"; public const string SimpleContainerSep = ",;|";
public static string GetSep(TType type) public static string GetBeanSep(TBean type)
{ {
if (type.Tags != null && type.Tags.TryGetValue("sep", out var s) && !string.IsNullOrWhiteSpace(s)) if (type.Tags != null && type.Tags.TryGetValue("sep", out var s) && !string.IsNullOrWhiteSpace(s))
{ {
return s; return s;
} }
switch (type) return ((DefBean)type.Bean).Sep;
{
case TBean tb: return (tb.Bean as DefBean).Sep;
case TArray ta: return ta.ElementType.Apply(IsNotSepTypeVisitor.Ins) ? SimpleContainerSep : "";
case TList ta: return ta.ElementType.Apply(IsNotSepTypeVisitor.Ins) ? SimpleContainerSep : "";
case TSet ta: return ta.ElementType.Apply(IsNotSepTypeVisitor.Ins) ? SimpleContainerSep : "";
default: return "";
}
} }
public static string GetTypeSep(TType type) public static string GetTypeSep(TType type)

View File

@ -47,7 +47,7 @@ namespace Luban.Job.Cfg.l10n
defTextRowType.PreCompile(); defTextRowType.PreCompile();
defTextRowType.Compile(); defTextRowType.Compile();
defTextRowType.PostCompile(); defTextRowType.PostCompile();
_textRowType = TBean.Create(false, defTextRowType); _textRowType = TBean.Create(false, defTextRowType, null);
} }
public void AddText(string key, string text) public void AddText(string key, string text)

View File

@ -87,37 +87,51 @@ namespace Luban.Job.Common.Defs
private readonly Dictionary<(DefTypeBase, bool), TType> _cacheDefTTypes = new Dictionary<(DefTypeBase, bool), TType>(); private readonly Dictionary<(DefTypeBase, bool), TType> _cacheDefTTypes = new Dictionary<(DefTypeBase, bool), TType>();
protected TType GetOrCreateTEnum(DefEnum defType, bool nullable) protected TType GetOrCreateTEnum(DefEnum defType, bool nullable, Dictionary<string, string> tags)
{ {
if (_cacheDefTTypes.TryGetValue((defType, nullable), out var t)) if (tags == null || tags.Count == 0)
{ {
return t; if (_cacheDefTTypes.TryGetValue((defType, nullable), out var t))
{
return t;
}
else
{
return _cacheDefTTypes[(defType, nullable)] = TEnum.Create(nullable, defType, tags);
}
} }
else else
{ {
return _cacheDefTTypes[(defType, nullable)] = TEnum.Create(nullable, defType); return TEnum.Create(nullable, defType, tags); ;
} }
} }
protected TType GetOrCreateTBean(DefTypeBase defType, bool nullable) protected TType GetOrCreateTBean(DefTypeBase defType, bool nullable, Dictionary<string, string> tags)
{ {
if (_cacheDefTTypes.TryGetValue((defType, nullable), out var t)) if (tags == null || tags.Count == 0)
{ {
return t; if (_cacheDefTTypes.TryGetValue((defType, nullable), out var t))
{
return t;
}
else
{
return _cacheDefTTypes[(defType, nullable)] = TBean.Create(nullable, (DefBeanBase)defType, tags);
}
} }
else else
{ {
return _cacheDefTTypes[(defType, nullable)] = TBean.Create(nullable, (DefBeanBase)defType); return TBean.Create(nullable, (DefBeanBase)defType, tags);
} }
} }
public TType GetDefTType(string module, string type, bool nullable) public TType GetDefTType(string module, string type, bool nullable, Dictionary<string, string> tags)
{ {
var defType = GetDefType(module, type); var defType = GetDefType(module, type);
switch (defType) switch (defType)
{ {
case DefBeanBase d: return GetOrCreateTBean(d, nullable); case DefBeanBase d: return GetOrCreateTBean(d, nullable, tags);
case DefEnum d: return GetOrCreateTEnum(d, nullable); case DefEnum d: return GetOrCreateTEnum(d, nullable, tags);
default: return null; default: return null;
} }
} }
@ -202,7 +216,7 @@ namespace Luban.Job.Common.Defs
case "datetime": return SupportDatetimeType ? TDateTime.Create(nullable, tags) : throw new NotSupportedException($"只有配置支持datetime数据类型"); case "datetime": return SupportDatetimeType ? TDateTime.Create(nullable, tags) : throw new NotSupportedException($"只有配置支持datetime数据类型");
default: default:
{ {
var dtype = GetDefTType(module, type, nullable); var dtype = GetDefTType(module, type, nullable, tags);
if (dtype != null) if (dtype != null)
{ {
return dtype; return dtype;

View File

@ -1,5 +1,6 @@
using Luban.Job.Common.Defs; using Luban.Job.Common.Defs;
using Luban.Job.Common.TypeVisitors; using Luban.Job.Common.TypeVisitors;
using Luban.Job.Common.Utils;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -7,9 +8,10 @@ namespace Luban.Job.Common.Types
{ {
public class TBean : TType public class TBean : TType
{ {
public static TBean Create(bool isNullable, DefBeanBase defBean) public static TBean Create(bool isNullable, DefBeanBase defBean, Dictionary<string, string> tags)
{ {
return new TBean(isNullable, defBean.Tags, defBean); // TODO
return new TBean(isNullable, DefUtil.MergeTags(defBean.Tags, tags), defBean);
} }
public DefBeanBase Bean { get; set; } public DefBeanBase Bean { get; set; }

View File

@ -1,5 +1,6 @@
using Luban.Job.Common.Defs; using Luban.Job.Common.Defs;
using Luban.Job.Common.TypeVisitors; using Luban.Job.Common.TypeVisitors;
using Luban.Job.Common.Utils;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -7,9 +8,9 @@ namespace Luban.Job.Common.Types
{ {
public class TEnum : TType public class TEnum : TType
{ {
public static TEnum Create(bool isNullable, DefEnum defEnum) public static TEnum Create(bool isNullable, DefEnum defEnum, Dictionary<string, string> tags)
{ {
return new TEnum(isNullable, defEnum.Tags, defEnum); return new TEnum(isNullable, DefUtil.MergeTags(defEnum.Tags, tags), defEnum);
} }
public DefEnum DefineEnum { get; } public DefEnum DefineEnum { get; }

View File

@ -1,4 +1,5 @@
using System; using Bright.Collections;
using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Luban.Job.Common.Utils namespace Luban.Job.Common.Utils
@ -123,7 +124,35 @@ namespace Luban.Job.Common.Utils
public static bool IsNormalFieldName(string name) public static bool IsNormalFieldName(string name)
{ {
return !name.StartsWith("__"); return !name.StartsWith("__") && !name.StartsWith("#");
}
public static Dictionary<string, string> MergeTags(Dictionary<string, string> tags1, Dictionary<string, string> tags2)
{
if (tags2 != null && tags2.Count > 0)
{
if (tags1 != null)
{
if (tags1.Count == 0)
{
return tags2;
}
else
{
var result = new Dictionary<string, string>(tags1);
result.AddAll(tags2);
return result;
}
}
else
{
return tags2;
}
}
else
{
return tags1;
}
} }
} }
} }