This is what you might like - recently at work I was looking for a way to "type" frequently used URL query string variables and developed this interface this way:
'Represent a named parameter that is passed from page-to-page via a range of methods- query strings, HTTP contexts, cookies, session, etc. Public Interface INamedParam 'A key that uniquely identfies this parameter in any HTTP value collection (query string, context, session, etc.) ReadOnly Property Key() As String 'The default value of the paramter. ReadOnly Property DefaultValue() As Object End Interface
Then you can implement this interface to describe the query string parameter, such an implementation for your "Hello" parameter might look like this:
Public Class HelloParam Implements INamedParam Public ReadOnly Property DefaultValue() As Object Implements INamedParam.DefaultValue Get Return "0" End Get End Property Public ReadOnly Property Key() As String Implements INamedParam.Key Get Return "hello" End Get End Property End Class
I developed a small (and very, very simple) class for creating URLs using these strongly typed parameters:
Public Class ParametrizedHttpUrlBuilder Private _RelativePath As String Private _QueryString As String Sub New(ByVal relativePath As String) _RelativePath = relativePath _QueryString = "" End Sub Public Sub AddQueryParameterValue(ByVal param As INamedParam, ByVal value As Object) Dim sb As New Text.StringBuilder(30) If _QueryString.Length > 0 Then sb.Append("&") End If sb.AppendFormat("{0}={1}", param.Key, value.ToString()) _QueryString &= sb.ToString() End Sub Public Property RelativePath() As String Get Return _RelativePath End Get Set(ByVal value As String) If value Is Nothing Then _RelativePath = "" End If _RelativePath = value End Set End Property Public ReadOnly Property Query() As String Get Return _QueryString End Get End Property Public ReadOnly Property PathAndQuery() As String Get Return _RelativePath & "?" & _QueryString End Get End Property End Class
source share