[fix] 修复 Proto及DB生成时,对于多级继承在某些遍历顺序下 CollectHierarchyFields 的bug

main
walon 2023-02-28 21:31:16 +08:00
parent c14437aa59
commit bcf81ffe26
6 changed files with 27 additions and 39 deletions

View File

@ -166,12 +166,12 @@ namespace Luban.Job.Cfg.Defs
public List<DefTable> GetAllTables() public List<DefTable> GetAllTables()
{ {
return Types.Values.Where(t => t is DefTable).Cast<DefTable>().ToList(); return TypeList.Where(t => t is DefTable).Cast<DefTable>().ToList();
} }
public List<DefTable> GetExportTables() public List<DefTable> GetExportTables()
{ {
return Types.Values.Where(t => t is DefTable ct return TypeList.Where(t => t is DefTable ct
&& !_outputExcludeTables.Contains(t.FullName) && !_outputExcludeTables.Contains(t.FullName)
&& (_outputIncludeTables.Contains(t.FullName) || (_overrideOutputTables == null ? ct.NeedExport : _overrideOutputTables.Contains(ct.FullName))) && (_outputIncludeTables.Contains(t.FullName) || (_overrideOutputTables == null ? ct.NeedExport : _overrideOutputTables.Contains(ct.FullName)))
).Select(t => (DefTable)t).ToList(); ).Select(t => (DefTable)t).ToList();
@ -313,12 +313,12 @@ namespace Luban.Job.Cfg.Defs
_cfgServices.AddRange(defines.Services); _cfgServices.AddRange(defines.Services);
foreach (var type in Types.Values) foreach (var type in TypeList)
{ {
type.AssemblyBase = this; type.AssemblyBase = this;
} }
foreach (var type in Types.Values) foreach (var type in TypeList)
{ {
try try
{ {
@ -332,7 +332,7 @@ namespace Luban.Job.Cfg.Defs
throw; throw;
} }
} }
foreach (var type in Types.Values) foreach (var type in TypeList)
{ {
try try
{ {
@ -348,7 +348,7 @@ namespace Luban.Job.Cfg.Defs
} }
} }
foreach (var type in Types.Values) foreach (var type in TypeList)
{ {
try try
{ {

View File

@ -158,29 +158,9 @@ namespace Luban.Job.Cfg.Defs
return null; return null;
} }
private void SetUpParent()
{
if (ParentDefType == null && !string.IsNullOrEmpty(Parent))
{
if ((ParentDefType = (DefBean)AssemblyBase.GetDefType(Namespace, Parent)) == null)
{
throw new Exception($"bean:'{FullName}' parent:'{Parent}' not exist");
}
if (ParentDefType.Children == null)
{
ParentDefType.Children = new List<DefBeanBase>();
}
ParentDefType.Children.Add(this);
((DefBean)ParentDefType).SetUpParent();
}
}
public override void PreCompile() public override void PreCompile()
{ {
SetUpParent(); base.PreCompile();
CollectHierarchyFields(HierarchyFields);
this.ExportFields = this.Fields.Select(f => (DefField)f).Where(f => f.NeedExport).ToList(); this.ExportFields = this.Fields.Select(f => (DefField)f).Where(f => f.NeedExport).ToList();
this.HierarchyExportFields = this.HierarchyFields.Select(f => (DefField)f).Where(f => f.NeedExport).ToList(); this.HierarchyExportFields = this.HierarchyFields.Select(f => (DefField)f).Where(f => f.NeedExport).ToList();
} }

View File

@ -34,6 +34,8 @@ namespace Luban.Job.Common.Defs
public Dictionary<string, DefTypeBase> Types { get; } = new Dictionary<string, DefTypeBase>(); public Dictionary<string, DefTypeBase> Types { get; } = new Dictionary<string, DefTypeBase>();
public List<DefTypeBase> TypeList { get; } = new List<DefTypeBase>();
private readonly Dictionary<string, DefTypeBase> _notCaseSenseTypes = new(); private readonly Dictionary<string, DefTypeBase> _notCaseSenseTypes = new();
private readonly HashSet<string> _namespaces = new(); private readonly HashSet<string> _namespaces = new();
@ -194,6 +196,7 @@ namespace Luban.Job.Common.Defs
} }
Types.Add(fullName, type); Types.Add(fullName, type);
TypeList.Add(type);
} }
public DefTypeBase GetDefType(string fullName) public DefTypeBase GetDefType(string fullName)

View File

@ -154,9 +154,9 @@ namespace Luban.Job.Common.Defs
fields.AddRange(Fields); fields.AddRange(Fields);
} }
public override void PreCompile() private void SetUpParentRecursively()
{ {
if (!string.IsNullOrEmpty(Parent)) if (ParentDefType == null && !string.IsNullOrEmpty(Parent))
{ {
if ((ParentDefType = (DefBeanBase)AssemblyBase.GetDefType(Namespace, Parent)) == null) if ((ParentDefType = (DefBeanBase)AssemblyBase.GetDefType(Namespace, Parent)) == null)
{ {
@ -167,8 +167,13 @@ namespace Luban.Job.Common.Defs
ParentDefType.Children = new List<DefBeanBase>(); ParentDefType.Children = new List<DefBeanBase>();
} }
ParentDefType.Children.Add(this); ParentDefType.Children.Add(this);
ParentDefType.SetUpParentRecursively();
}
} }
public override void PreCompile()
{
SetUpParentRecursively();
CollectHierarchyFields(HierarchyFields); CollectHierarchyFields(HierarchyFields);
} }

View File

@ -48,12 +48,12 @@ namespace Luban.Job.Db.Defs
AddType(new DefTable(p)); AddType(new DefTable(p));
} }
foreach (var type in Types.Values) foreach (var type in TypeList)
{ {
type.AssemblyBase = this; type.AssemblyBase = this;
} }
foreach (var type in Types.Values) foreach (var type in TypeList)
{ {
try try
{ {
@ -67,7 +67,7 @@ namespace Luban.Job.Db.Defs
throw; throw;
} }
} }
foreach (var type in Types.Values) foreach (var type in TypeList)
{ {
try try
{ {
@ -82,7 +82,7 @@ namespace Luban.Job.Db.Defs
throw; throw;
} }
} }
foreach (var type in Types.Values) foreach (var type in TypeList)
{ {
try try
{ {
@ -101,7 +101,7 @@ namespace Luban.Job.Db.Defs
public List<DefTypeBase> GetExportTypes() public List<DefTypeBase> GetExportTypes()
{ {
return Types.Values.ToList(); return TypeList;
} }
} }
} }

View File

@ -50,12 +50,12 @@ namespace Luban.Job.Proto.Defs
AddType(new DefRpc(r)); AddType(new DefRpc(r));
} }
foreach (var type in Types.Values) foreach (var type in TypeList)
{ {
type.AssemblyBase = this; type.AssemblyBase = this;
} }
foreach (var type in Types.Values) foreach (var type in TypeList)
{ {
try try
{ {
@ -69,7 +69,7 @@ namespace Luban.Job.Proto.Defs
throw; throw;
} }
} }
foreach (var type in Types.Values) foreach (var type in TypeList)
{ {
try try
{ {
@ -84,7 +84,7 @@ namespace Luban.Job.Proto.Defs
throw; throw;
} }
} }
foreach (var type in Types.Values) foreach (var type in TypeList)
{ {
try try
{ {
@ -104,7 +104,7 @@ namespace Luban.Job.Proto.Defs
public List<DefTypeBase> GetExportTypes() public List<DefTypeBase> GetExportTypes()
{ {
return Types.Values.ToList(); return TypeList;
} }
} }
} }