@@ -41,7 +41,7 @@ public static List<DefinedColumn> Flatten(ExcelHeaderFile exh, Sheet sheet, bool
41
41
{
42
42
var fields = new List < Field > ( ) ;
43
43
foreach ( var field in sheet . Fields )
44
- Emit ( fields , field , null , usePath ) ;
44
+ Emit ( fields , field , null ) ;
45
45
46
46
var exhDefList = exh . ColumnDefinitions . ToList ( ) ;
47
47
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
59
59
return definedColumns ;
60
60
}
61
61
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 = "" )
63
63
{
64
64
if ( field . Type != FieldType . Array )
65
65
{
66
66
// Single field
67
- list . Add ( CreateField ( field , false , 0 , hierarchy , usePath ) ) ;
67
+ list . Add ( CreateField ( field , false , 0 , hierarchy , nameOverride ) ) ;
68
68
}
69
69
else if ( field . Type == FieldType . Array )
70
70
{
@@ -73,7 +73,7 @@ private static void Emit(List<Field> list, Field field, List<string> hierarchy =
73
73
{
74
74
for ( int i = 0 ; i < field . Count . Value ; i ++ )
75
75
{
76
- list . Add ( CreateField ( field , true , i , hierarchy , usePath ) ) ;
76
+ list . Add ( CreateField ( field , true , i , hierarchy , "" ) ) ;
77
77
}
78
78
}
79
79
else
@@ -82,22 +82,22 @@ private static void Emit(List<Field> list, Field field, List<string> hierarchy =
82
82
{
83
83
foreach ( var nestedField in field . Fields )
84
84
{
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 ) ;
86
86
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 ) ;
91
90
}
92
91
}
93
92
}
94
93
}
95
94
}
96
95
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 )
98
97
{
99
98
var addedField = new Field
100
99
{
100
+ Name = baseField . Name ,
101
101
Comment = baseField . Comment ,
102
102
Count = null ,
103
103
Type = baseField . Type == FieldType . Array ? FieldType . Scalar : baseField . Type ,
@@ -106,25 +106,32 @@ private static Field CreateField(Field baseField, bool fieldIsArrayElement, int
106
106
Targets = baseField . Targets ,
107
107
} ;
108
108
109
- var name = $ "{ baseField . Name } ";
109
+ var path = $ "{ baseField . Name } ";
110
+ var path2 = $ "{ baseField . Name } ";
110
111
111
112
if ( fieldIsArrayElement )
112
113
{
113
- name = $ "{ name } ";
114
- if ( ! usePath )
115
- name += $ "[{ index } ]";
114
+ path2 += $ "[{ index } ]";
116
115
}
117
116
118
117
if ( hierarchy != null )
119
118
{
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 } ";
123
123
}
124
124
else
125
125
{
126
- addedField . Name = name ;
126
+ addedField . Path = path ;
127
+ addedField . PathWithArrayIndices = path2 ;
127
128
}
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
+
128
135
return addedField ;
129
136
}
130
137
0 commit comments