我所知道的不存在。这是一些简单的事情,可以满足您的需求。用法是:
UrlBuilder ub = new UrlBuilder("www.google.com/search")
.AddQuery("q", "request")
.AddQuery("sourceid", "ie8");
string url=ub.ToString();
==
代码是:
public class UrlBuilder
{
private string _authority;
private string _host;
private int? _port;
private Dictionary<string, object> _query = new Dictionary<string, object>();
public UrlBuilder(string host)
: this("http", host, null)
{
}
public UrlBuilder(string authority, string host)
: this(authority, host, null)
{
}
public UrlBuilder(string authority, string host, int? port)
{
this._authority = authority;
this._host = host;
this._port = port;
}
public UrlBuilder AddQuery(string key, object value)
{
this._query.Add(key, value);
return this;
}
public override string ToString()
{
string url = _authority + "://" + _host;
if (_port.HasValue)
{
url += ":" + _port.ToString();
}
return AppendQuery(url);
}
private string AppendQuery(string url)
{
if (_query.Count == 0)
{
return url;
}
url += "?";
bool isNotFirst = false;
foreach (var key in this._query.Keys)
{
if (isNotFirst)
{
url += "&";
}
url += HttpUtility.UrlEncode(key) + "=" + HttpUtility.UrlEncode(this._query[key].ToString());
isNotFirst = true;
}
return url;
}
}
}