TableNode RowHeirarchyIterator(int columnIndex, int rowIndex, int maxNestColumnCount, int rowIndent, ref int endIndex) { bool bNodeCachedByList = true; int enumColumnIndex = columnIndex; if (!FilterEmptyColumn(ref enumColumnIndex) || !CacheNestTableType(enumColumnIndex, out bNodeCachedByList)) { endIndex = ++enumColumnIndex; return(null); } bool firstEle = true; bool bNestInArray = false; int cachedEleCount = 0; int nestEleCount = maxNestColumnCount; var curRowNode = new TableListNode(columnCount - columnIndex); TableNode rowRootNode = curRowNode; if (!bNodeCachedByList && rowIndent > 1) { var tempDicNode = new TableDicNode(columnCount - columnIndex); tempDicNode.Add(rowsInfo[rowIndex][enumColumnIndex], curRowNode); tempDicNode.Desc = tableCellDescList[enumColumnIndex]; rowRootNode = tempDicNode; } while (true) { int subNestEleCount = 1; string cellTag = tableNestTagList[enumColumnIndex]; string cellType = tableCellTypeList[enumColumnIndex]; TableNode subNode = rowsInfo[rowIndex][enumColumnIndex]; if (SerializeNestDataLength(cellTag, maxNestColumnCount, ref subNestEleCount) || subNestEleCount != -1) { int tempEndIndex = enumColumnIndex + 1; if (firstEle) { nestEleCount = subNestEleCount; if (Regex.IsMatch(cellTag, limitLengthArrayTagRegex) && nestEleCount > 1) { bNestInArray = true; } nestEleCount = Math.Min(maxNestColumnCount, nestEleCount); } else if (subNestEleCount > 1) { tempEndIndex = endIndex; subNode = RowHeirarchyIterator(enumColumnIndex, rowIndex, maxNestColumnCount - 1, ++rowIndent, ref tempEndIndex); } subNode.Desc = tableCellDescList[enumColumnIndex]; subNode.NestInTable(tableCellNameList[enumColumnIndex]); enumColumnIndex = tempEndIndex; } else { endIndex = ++enumColumnIndex; return(null); } ++cachedEleCount; if (bNodeCachedByList || (!bNodeCachedByList && !firstEle)) { curRowNode.Add(subNode); } if (bNestInArray) { subNode.NestInArray(); } firstEle = false; if (enumColumnIndex >= endIndex || enumColumnIndex >= columnCount || cachedEleCount >= nestEleCount) { endIndex = enumColumnIndex; break; } } return(rowRootNode); }
void TabelHeirarchyIterator() { bool bItorEnd = false; int startColumnIndex = 0; FilterEmptyColumn(ref startColumnIndex); if (columnsInfo.Count == 0) { columnsInfo.Add(startColumnIndex, rowCount - nestTagRowIndex - 1); } tableColumnNodeList = new TableListNode(columnsInfo.Count); Dictionary <int, int> .Enumerator itor = columnsInfo.GetEnumerator(); itor.MoveNext(); while (!bItorEnd) { startColumnIndex = itor.Current.Key; int partialRowCount = itor.Current.Value; int nestColumnEleCount = columnCount - startColumnIndex; if (itor.MoveNext()) { nestColumnEleCount = itor.Current.Key - startColumnIndex; } else { bItorEnd = true; } if (Regex.IsMatch(tableNestTagList[startColumnIndex], columnTagRegex)) { /// 默认不管该列配了多少个数据,只读一个数据,要读多行数据请在“行”中实现 var subNode = rowsInfo[nestTagRowIndex + 1][startColumnIndex]; subNode.NestInTable(tableCellNameList[startColumnIndex]); tableColumnNodeList.Add(subNode); ++startColumnIndex; --nestColumnEleCount; if (nestColumnEleCount <= 0) { continue; } } bool bCacheByList = true; if (!CacheNestTableType(startColumnIndex, out bCacheByList)) { itor.Dispose(); return; } int endIndex = nestColumnEleCount + startColumnIndex; if (bCacheByList) { var curListNode = new TableListNode(partialRowCount); for (int j = nestTagRowIndex + 1, len = partialRowCount + nestTagRowIndex + 1; j < len; ++j) { curListNode.Add(RowHeirarchyIterator(startColumnIndex, j, nestColumnEleCount, 1, ref endIndex)); } tableColumnNodeList.Add(curListNode); } else { var curDicNode = new TableDicNode(partialRowCount); curDicNode.Desc = tableCellDescList[startColumnIndex]; for (int j = nestTagRowIndex + 1, len = partialRowCount + nestTagRowIndex + 1; j < len; ++j) { TableNode newNode = RowHeirarchyIterator(startColumnIndex, j, nestColumnEleCount, 1, ref endIndex); curDicNode.Add(rowsInfo[j][startColumnIndex], newNode); } tableColumnNodeList.Add(curDicNode); } } itor.Dispose(); }