112 lines
2.4 KiB
C#
112 lines
2.4 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Specialized;
|
|
using System.Web;
|
|
namespace SPSolutions.Web
|
|
{
|
|
public class QueryString : NameValueCollection
|
|
{
|
|
private string document;
|
|
public string Document
|
|
{
|
|
get
|
|
{
|
|
return this.document;
|
|
}
|
|
}
|
|
public QueryString()
|
|
{
|
|
}
|
|
public QueryString(NameValueCollection clone) : base(clone)
|
|
{
|
|
}
|
|
public static QueryString FromCurrent()
|
|
{
|
|
return QueryString.FromUrl(HttpContext.Current.Request.Url.AbsoluteUri);
|
|
}
|
|
public static QueryString FromUrl(string url)
|
|
{
|
|
string[] array = url.Split("?".ToCharArray());
|
|
QueryString queryString = new QueryString();
|
|
queryString.document = array[0];
|
|
if (array.Length == 1)
|
|
{
|
|
return queryString;
|
|
}
|
|
string[] array2 = array[1].Split("&".ToCharArray());
|
|
string[] array3 = array2;
|
|
for (int i = 0; i < array3.Length; i++)
|
|
{
|
|
string text = array3[i];
|
|
string[] array4 = text.Split("=".ToCharArray());
|
|
if (array4.Length == 1)
|
|
{
|
|
queryString.Add(array4[0], "");
|
|
}
|
|
queryString.Add(array4[0], array4[1]);
|
|
}
|
|
return queryString;
|
|
}
|
|
public void ClearAllExcept(string except)
|
|
{
|
|
this.ClearAllExcept(new string[]
|
|
{
|
|
except
|
|
});
|
|
}
|
|
public void ClearAllExcept(string[] except)
|
|
{
|
|
ArrayList arrayList = new ArrayList();
|
|
string[] allKeys = this.AllKeys;
|
|
for (int i = 0; i < allKeys.Length; i++)
|
|
{
|
|
string text = allKeys[i];
|
|
for (int j = 0; j < except.Length; j++)
|
|
{
|
|
string text2 = except[j];
|
|
if (text.ToLower() == text2.ToLower() && !arrayList.Contains(text))
|
|
{
|
|
arrayList.Add(text);
|
|
}
|
|
}
|
|
}
|
|
foreach (string name in arrayList)
|
|
{
|
|
this.Remove(name);
|
|
}
|
|
}
|
|
public override void Add(string name, string value)
|
|
{
|
|
if (base[name] != null)
|
|
{
|
|
base[name] = value;
|
|
return;
|
|
}
|
|
base.Add(name, value);
|
|
}
|
|
public override string ToString()
|
|
{
|
|
return this.ToString(false);
|
|
}
|
|
public string ToString(bool includeUrl)
|
|
{
|
|
string[] array = new string[this.Count];
|
|
string[] allKeys = this.AllKeys;
|
|
for (int i = 0; i < allKeys.Length; i++)
|
|
{
|
|
array[i] = allKeys[i] + "=" + HttpUtility.UrlEncode(base[allKeys[i]]);
|
|
}
|
|
string text = string.Join("&", array);
|
|
if (!string.IsNullOrEmpty(text) && !text.StartsWith("?"))
|
|
{
|
|
text = "?" + text;
|
|
}
|
|
if (includeUrl)
|
|
{
|
|
text = this.document + text;
|
|
}
|
|
return text;
|
|
}
|
|
}
|
|
}
|