Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Region " Imports "
- Imports System.ComponentModel
- Imports System.Runtime.CompilerServices
- Imports System.Text
- Imports System.Web
- #End Region
- #Region " NameValueCollection Extensions "
- Namespace ElektroKit.Core.Extensions.[NameValueCollection]
- ''' <summary>Contains custom extension methods to use with an <see cref="Collections.Specialized.NameValueCollection"/>.</summary>
- <HideModuleName>
- Public Module NameValueCollectionExtensions
- <DebuggerStepThrough>
- <Extension>
- <EditorBrowsable(EditorBrowsableState.Always)>
- Public Function ToQueryString(sender As Collections.Specialized.NameValueCollection,
- baseAddress As Uri) As String
- Return NameValueCollectionExtensions.ToQueryString(sender, baseAddress.AbsoluteUri)
- End Function
- <DebuggerStepThrough>
- <Extension>
- <EditorBrowsable(EditorBrowsableState.Always)>
- Public Function ToQueryString(sender As Collections.Specialized.NameValueCollection,
- baseAddress As String) As String
- Dim sb As New StringBuilder
- If Not String.IsNullOrWhiteSpace(baseAddress) Then
- sb.Append(baseAddress.TrimEnd({"?"c}))
- sb.Append("?")
- End If
- For Each key As String In sender.AllKeys
- sb.AppendFormat("{0}={1}&", key, HttpUtility.UrlEncode(sender(key)))
- Next
- Return sb.Remove((sb.Length - 1), 1).ToString() ' removes the last "&" char.
- End Function
- End Module
- End Namespace
- #End Region
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement