50 lines
1.5 KiB
VB.net
50 lines
1.5 KiB
VB.net
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
|