/// <summary>
 /// Provides culture-invariant serialization of value types, in lower case for querystring readability. Setting a key to null removes it.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="q"></param>
 /// <param name="name"></param>
 /// <param name="val"></param>
 /// <returns></returns>
 public static NameValueCollection Set <T>(this NameValueCollection q, string name, T?val) where T : struct, IConvertible
 {
     if (!val.HasValue)
     {
         q.Remove(name);
     }
     else
     {
         q[name] = NameValueCollectionExtensions.SerializePrimitive <T>(val);
     }
     return(q);
 }
        private static string JoinPrimitives <T>(T[] array, char delimiter) where T : struct, IConvertible
        {
            StringBuilder stringBuilder = new StringBuilder();

            for (int index = 0; index < array.Length; ++index)
            {
                stringBuilder.Append(NameValueCollectionExtensions.SerializePrimitive <T>(new T?(array[index])));
                if (index < array.Length - 1)
                {
                    stringBuilder.Append(delimiter);
                }
            }
            return(stringBuilder.ToString());
        }