ImportZUGFeRDFiles: Add Importing of grouped items

This commit is contained in:
Jonathan Jenne
2019-05-10 14:14:13 +02:00
parent ce21ae5dab
commit 15c33b843e
2 changed files with 81 additions and 23 deletions

View File

@@ -7,10 +7,17 @@ Public Class PropertyValues
Private Shared _indexRegex As New Regex(_indexPattern)
Public Shared Function GetPropValues(Obj As Object, PropertyName As String)
Dim oResult As Object = GetPropValue(Obj, PropertyName)
' Wrap the result of `GetPropValue` in a list if a single Value is returned
If TypeOf oResult Is List(Of Object) Then
Return oResult
Else
Return New List(Of Object) From {oResult}
End If
End Function
Public Shared Function GetPropValue(Obj As Object, PropertyName As String, Optional ReturnWhenEmpty As Boolean = True)
Public Shared Function GetPropValue(Obj As Object, PropertyName As String)
Dim oNameParts As String() = PropertyName.Split("."c)
If IsNothing(Obj) Then
@@ -49,14 +56,18 @@ Public Class PropertyValues
End If
If IsArray(Obj) And Not oHasIndex Then
Dim oCurrentPart = oPart
Dim oPathFragment = PropertyName.
Split(New String() {"." & oCurrentPart & "."}, StringSplitOptions.None)
Dim oCurrentPart As String = oPart
Dim oSplitString As String() = New String() {"." & oCurrentPart & "."}
Dim oPathFragments = PropertyName.Split(oSplitString, StringSplitOptions.None)
Dim oResults As New List(Of Object)
' if path has no more subitems, return an empty list
If oPathFragments.Length = 1 Then
Return oResults
End If
For Each oArrayItem In Obj
Dim oResult = GetPropValue(oArrayItem, oPathFragment(1), ReturnWhenEmpty:=False)
Dim oResult = GetPropValue(oArrayItem, oPathFragments(1))
If Not IsNothing(oResult) Then
oResults.Add(oResult)