Consolidate parameter format and logic

This commit is contained in:
Jonathan Jenne
2022-06-20 15:00:49 +02:00
parent b3140c48c5
commit adad5501f3
4 changed files with 58 additions and 42 deletions

View File

@@ -0,0 +1,49 @@
Imports DigitalData.Modules.Logging
Public Class Parameters
''' <summary>
''' Parse a list of parameters and return a directory of the parsed parameters.
''' </summary>
''' <remarks>The special case of SQL Parameters is NOT handled by this function.</remarks>
Public Shared Function Parse(pParameters As String) As Dictionary(Of String, String)
Try
Dim oParamsDict As New Dictionary(Of String, String)
If pParameters <> String.Empty Then
Dim oParamList = pParameters.Split("|").ToList()
For Each oParam In oParamList
Dim oParamSplit = oParam.Split("=")
If oParamSplit.Count = 2 Then
oParamsDict.Add(oParamSplit(0), oParamSplit(1))
End If
Next
End If
Return oParamsDict
Catch ex As Exception
Return New Dictionary(Of String, String)
End Try
End Function
Public Shared Function TryGet(pParameters As String, pName As String) As Tuple(Of String, String)
Try
Dim pParamDict = Parse(pParameters)
If pParamDict.Count = 0 Then
Return Nothing
End If
If Not pParamDict.ContainsKey(pName) Then
Return Nothing
End If
Dim oValue = pParamDict.Item(pName)
Return New Tuple(Of String, String)(pName, oValue)
Catch ex As Exception
Return Nothing
End Try
End Function
End Class