I have a string representing an object property:
Dim path = "Person.AddressHistory(0).Street1"
and I am splitting it using path.Split("."C). Then I am iterating through it using a For-Each loop. I want to check if any of the "path sections" (or property names), such as AddressHistory(0) contains parentheses and an index value, then I wish to extract the index value (in this case the integer 0).
I will then eventually be able to use this technique to find the value of the last path section, i.e. Street1 (or any value pointed to by a given path).
I don't know much about visual basic regex or string parsing though. So far I have this:
Private Function GetValue(root As Object, path As String) As Object
Dim pathSections = path.Split("."C)
For Each section In pathSections
Dim index As Integer
Dim info As System.Reflection.PropertyInfo
If section.Contains("(%d)") Then
'todo: get index...
'index = section.<Get index using regex>()
End If
' reflection to get next property value
' root = <get next value...>
Next
Return root
End Function