Show / Hide Table of Contents

Class NameValueCollectionOps

Inheritance
object
NameValueCollectionOps
Inherited Members
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
Namespace: SuperOffice.Util
Assembly: SoCore.dll
Syntax
public static class NameValueCollectionOps

Methods

CreateNameValueCollection(string)

Create a NameValueCollection from a string in standard name/value format

Declaration
public static NameValueCollection CreateNameValueCollection(string nameValueString)
Parameters
Type Name Description
string nameValueString

Name/value input string

Returns
Type Description
NameValueCollection

Equivalent collection

Remarks

The input string should be of the format key=value&key2=value2 etc. Duplicate keys are acceptable. An empty or null input string will result in an empty (not null) return value.

The System.Web.HttpUtility.ParseQueryString method is used for the parsing, so that URL-encoded data values are handled correctly

CreateNameValueString(NameValueCollection)

Create a name/value string from a NameValueCollection.

Declaration
public static string CreateNameValueString(NameValueCollection nameValueCollection)
Parameters
Type Name Description
NameValueCollection nameValueCollection

Collection to be converted

Returns
Type Description
string

Name/value string corresponding to the collection

Remarks

Duplicate keys in the incoming collection will result in duplicate keys in the output. An empty or null input will return an empty (not null) string.

The ToString() method of the NameValueCollection class CANNOT BE used to create the string. The framework claims that Request.QueryString is a NameValueCollection, but at runtime, it's actually a System.Web.HttpValueCollection. The difference is significant because HttpValueCollection.ToString() returns the URL-encoded raw query string, but NameValueCollection.ToString() returns the default Object.ToString() result - in this case "System.Collections.Specialized.NameValueCollection"

Thanks to http://dylanbeattie.blogspot.com/2008/12/mocking-querystring-collection-in.html for this little gem, which could otherwise do incredible damage. Fuck Microsoft for doing things like this.

We urlencode the values, since they might contain ampersands that would then scupper us later on...
© SuperOffice. All rights reserved.
SuperOffice |  Community |  Release Notes |  Privacy |  Site feedback |  Search Docs |  About Docs |  Contribute |  Back to top