【修复】修复enum与bean没有正确处理tags导致枚举类型字段无法正确生成ref的bug
parent
e54870fb02
commit
38b410f0a5
11
README.md
11
README.md
|
|
@ -158,7 +158,16 @@ array与list类型都能表示列表,它们区别在于array生成的代码为
|
|||
<tr align="center">
|
||||
<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>aaaa|bbbb|cccc</td>
|
||||
<td>aaa</td><td>bbb</td><td>ccc</td>
|
||||
|
|
|
|||
|
|
@ -481,7 +481,7 @@ namespace Luban.Job.Cfg.DataCreators
|
|||
|
||||
public DType Accept(TMap type, Sheet sheet, TitleRow row)
|
||||
{
|
||||
string sep = DataUtil.GetSep(type);
|
||||
string sep = "";
|
||||
|
||||
if (row.Row != null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -418,7 +418,7 @@ namespace Luban.Job.Cfg.Defs
|
|||
defTableRecordType.PreCompile();
|
||||
defTableRecordType.Compile();
|
||||
defTableRecordType.PostCompile();
|
||||
var tableRecordType = TBean.Create(false, defTableRecordType);
|
||||
var tableRecordType = TBean.Create(false, defTableRecordType, null);
|
||||
|
||||
foreach (var file in inputFileInfos)
|
||||
{
|
||||
|
|
@ -485,7 +485,7 @@ namespace Luban.Job.Cfg.Defs
|
|||
defTableRecordType.PreCompile();
|
||||
defTableRecordType.Compile();
|
||||
defTableRecordType.PostCompile();
|
||||
var tableRecordType = TBean.Create(false, defTableRecordType);
|
||||
var tableRecordType = TBean.Create(false, defTableRecordType, null);
|
||||
|
||||
foreach (var file in inputFileInfos)
|
||||
{
|
||||
|
|
@ -592,7 +592,7 @@ namespace Luban.Job.Cfg.Defs
|
|||
defTableRecordType.PreCompile();
|
||||
defTableRecordType.Compile();
|
||||
defTableRecordType.PostCompile();
|
||||
var tableRecordType = TBean.Create(false, defTableRecordType);
|
||||
var tableRecordType = TBean.Create(false, defTableRecordType, null);
|
||||
|
||||
foreach (var file in inputFileInfos)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -139,23 +139,15 @@ namespace Luban.Job.Cfg.Utils
|
|||
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))
|
||||
{
|
||||
return s;
|
||||
}
|
||||
switch (type)
|
||||
{
|
||||
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 "";
|
||||
}
|
||||
return ((DefBean)type.Bean).Sep;
|
||||
}
|
||||
|
||||
public static string GetTypeSep(TType type)
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ namespace Luban.Job.Cfg.l10n
|
|||
defTextRowType.PreCompile();
|
||||
defTextRowType.Compile();
|
||||
defTextRowType.PostCompile();
|
||||
_textRowType = TBean.Create(false, defTextRowType);
|
||||
_textRowType = TBean.Create(false, defTextRowType, null);
|
||||
}
|
||||
|
||||
public void AddText(string key, string text)
|
||||
|
|
|
|||
|
|
@ -87,7 +87,9 @@ namespace Luban.Job.Common.Defs
|
|||
|
||||
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 (tags == null || tags.Count == 0)
|
||||
{
|
||||
if (_cacheDefTTypes.TryGetValue((defType, nullable), out var t))
|
||||
{
|
||||
|
|
@ -95,11 +97,18 @@ namespace Luban.Job.Common.Defs
|
|||
}
|
||||
else
|
||||
{
|
||||
return _cacheDefTTypes[(defType, nullable)] = TEnum.Create(nullable, defType);
|
||||
return _cacheDefTTypes[(defType, nullable)] = TEnum.Create(nullable, defType, tags);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
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 (tags == null || tags.Count == 0)
|
||||
{
|
||||
if (_cacheDefTTypes.TryGetValue((defType, nullable), out var t))
|
||||
{
|
||||
|
|
@ -107,17 +116,22 @@ namespace Luban.Job.Common.Defs
|
|||
}
|
||||
else
|
||||
{
|
||||
return _cacheDefTTypes[(defType, nullable)] = TBean.Create(nullable, (DefBeanBase)defType);
|
||||
return _cacheDefTTypes[(defType, nullable)] = TBean.Create(nullable, (DefBeanBase)defType, tags);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
switch (defType)
|
||||
{
|
||||
case DefBeanBase d: return GetOrCreateTBean(d, nullable);
|
||||
case DefEnum d: return GetOrCreateTEnum(d, nullable);
|
||||
case DefBeanBase d: return GetOrCreateTBean(d, nullable, tags);
|
||||
case DefEnum d: return GetOrCreateTEnum(d, nullable, tags);
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -202,7 +216,7 @@ namespace Luban.Job.Common.Defs
|
|||
case "datetime": return SupportDatetimeType ? TDateTime.Create(nullable, tags) : throw new NotSupportedException($"只有配置支持datetime数据类型");
|
||||
default:
|
||||
{
|
||||
var dtype = GetDefTType(module, type, nullable);
|
||||
var dtype = GetDefTType(module, type, nullable, tags);
|
||||
if (dtype != null)
|
||||
{
|
||||
return dtype;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using Luban.Job.Common.Defs;
|
||||
using Luban.Job.Common.TypeVisitors;
|
||||
using Luban.Job.Common.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
|
@ -7,9 +8,10 @@ namespace Luban.Job.Common.Types
|
|||
{
|
||||
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; }
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using Luban.Job.Common.Defs;
|
||||
using Luban.Job.Common.TypeVisitors;
|
||||
using Luban.Job.Common.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
|
@ -7,9 +8,9 @@ namespace Luban.Job.Common.Types
|
|||
{
|
||||
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; }
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using Bright.Collections;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Luban.Job.Common.Utils
|
||||
|
|
@ -123,7 +124,35 @@ namespace Luban.Job.Common.Utils
|
|||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue