Skip to content

Commit 703f950

Browse files
committed
Add new nonserialized fields into the sheet definition for more accurate validation processing
1 parent 2457a57 commit 703f950

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

EXDCommon/SchemaModel/NewSheetDefinition.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ public class Field
6868
/// </summary>
6969
[YamlIgnore]
7070
public int FieldCount;
71+
72+
/// <summary>
73+
/// Field path in the form "Field.Subfield.Subsubfield"
74+
/// </summary>
75+
[YamlIgnore]
76+
public string Path;
77+
78+
/// <summary>
79+
/// Field path in the form "Field[0].Subfield[1].Subsubfield[2]"
80+
/// </summary>
81+
[YamlIgnore]
82+
public string PathWithArrayIndices;
7183

7284
public override string ToString()
7385
{

EXDCommon/Utility/SchemaUtil.cs

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static List<DefinedColumn> Flatten(ExcelHeaderFile exh, Sheet sheet, bool
4141
{
4242
var fields = new List<Field>();
4343
foreach (var field in sheet.Fields)
44-
Emit(fields, field, null, usePath);
44+
Emit(fields, field, null);
4545

4646
var exhDefList = exh.ColumnDefinitions.ToList();
4747
exhDefList.Sort((c1, c2) => DefinedColumn.CalculateBitOffset(c1).CompareTo(DefinedColumn.CalculateBitOffset(c2)));
@@ -59,12 +59,12 @@ public static List<DefinedColumn> Flatten(ExcelHeaderFile exh, Sheet sheet, bool
5959
return definedColumns;
6060
}
6161

62-
private static void Emit(List<Field> list, Field field, List<string> hierarchy = null, bool usePath = false)
62+
private static void Emit(List<Field> list, Field field, List<(string, string)> hierarchy = null, string nameOverride = "")
6363
{
6464
if (field.Type != FieldType.Array)
6565
{
6666
// Single field
67-
list.Add(CreateField(field, false, 0, hierarchy, usePath));
67+
list.Add(CreateField(field, false, 0, hierarchy, nameOverride));
6868
}
6969
else if (field.Type == FieldType.Array)
7070
{
@@ -73,7 +73,7 @@ private static void Emit(List<Field> list, Field field, List<string> hierarchy =
7373
{
7474
for (int i = 0; i < field.Count.Value; i++)
7575
{
76-
list.Add(CreateField(field, true, i, hierarchy, usePath));
76+
list.Add(CreateField(field, true, i, hierarchy, ""));
7777
}
7878
}
7979
else
@@ -82,22 +82,22 @@ private static void Emit(List<Field> list, Field field, List<string> hierarchy =
8282
{
8383
foreach (var nestedField in field.Fields)
8484
{
85-
var usableHierarchy = hierarchy == null ? new List<string>() : new List<string>(hierarchy);
85+
var usableHierarchy = hierarchy == null ? new List<(string, string)>() : new List<(string, string)>(hierarchy);
8686
var hierarchyName = $"{field.Name}";
87-
if (!usePath)
88-
hierarchyName += $"[{i}]";
89-
usableHierarchy.Add(hierarchyName);
90-
Emit(list, nestedField, usableHierarchy, usePath);
87+
var hierarchyName2 = $"{field.Name}[{i}]";
88+
usableHierarchy.Add((hierarchyName, hierarchyName2));
89+
Emit(list, nestedField, usableHierarchy, field.Name);
9190
}
9291
}
9392
}
9493
}
9594
}
9695

97-
private static Field CreateField(Field baseField, bool fieldIsArrayElement, int index, List<string> hierarchy, bool usePath)
96+
private static Field CreateField(Field baseField, bool fieldIsArrayElement, int index, List<(string, string)>? hierarchy, string nameOverride)
9897
{
9998
var addedField = new Field
10099
{
100+
Name = baseField.Name,
101101
Comment = baseField.Comment,
102102
Count = null,
103103
Type = baseField.Type == FieldType.Array ? FieldType.Scalar : baseField.Type,
@@ -106,25 +106,32 @@ private static Field CreateField(Field baseField, bool fieldIsArrayElement, int
106106
Targets = baseField.Targets,
107107
};
108108

109-
var name = $"{baseField.Name}";
109+
var path = $"{baseField.Name}";
110+
var path2 = $"{baseField.Name}";
110111

111112
if (fieldIsArrayElement)
112113
{
113-
name = $"{name}";
114-
if (!usePath)
115-
name += $"[{index}]";
114+
path2 += $"[{index}]";
116115
}
117116

118117
if (hierarchy != null)
119118
{
120-
addedField.Name = string.Join(".", hierarchy);
121-
if (!string.IsNullOrEmpty(name))
122-
addedField.Name += $".{name}";
119+
addedField.Path = string.Join(".", hierarchy);
120+
addedField.PathWithArrayIndices = string.Join(".", hierarchy);
121+
if (!string.IsNullOrEmpty(path)) addedField.Path += $".{path}";
122+
if (!string.IsNullOrEmpty(path)) addedField.PathWithArrayIndices += $".{path2}";
123123
}
124124
else
125125
{
126-
addedField.Name = name;
126+
addedField.Path = path;
127+
addedField.PathWithArrayIndices = path2;
127128
}
129+
130+
// This is for unnamed inner fields of arrays such as arrays of links
131+
// We don't want to override the name of unnamed scalars though
132+
if (baseField.Name == null && baseField.Type != FieldType.Scalar && nameOverride != "")
133+
addedField.Name = nameOverride;
134+
128135
return addedField;
129136
}
130137

0 commit comments

Comments
 (0)