WebUtilities: Add more query helpers.
This commit is contained in:
parent
bc0732f900
commit
1aed739edb
|
|
@ -1,4 +1,7 @@
|
||||||
using System;
|
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.WebUtilities
|
namespace Microsoft.AspNet.WebUtilities
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,9 @@
|
||||||
using System;
|
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.WebUtilities
|
namespace Microsoft.AspNet.WebUtilities
|
||||||
{
|
{
|
||||||
|
|
@ -16,5 +21,27 @@ namespace Microsoft.AspNet.WebUtilities
|
||||||
bool hasQuery = uri.IndexOf('?') != -1;
|
bool hasQuery = uri.IndexOf('?') != -1;
|
||||||
return uri + (hasQuery ? "&" : "?") + Uri.EscapeDataString(name) + "=" + Uri.EscapeDataString(value);
|
return uri + (hasQuery ? "&" : "?") + Uri.EscapeDataString(name) + "=" + Uri.EscapeDataString(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Append the given query keys and values to the uri.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="uri">The base uri.</param>
|
||||||
|
/// <param name="queryString">A collection of name value query pairs to append.</param>
|
||||||
|
/// <returns>The combine result.</returns>
|
||||||
|
public static string AddQueryString([NotNull] string uri, [NotNull] IDictionary<string, string> queryString)
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
sb.Append(uri);
|
||||||
|
bool hasQuery = uri.IndexOf('?') != -1;
|
||||||
|
foreach (var parameter in queryString)
|
||||||
|
{
|
||||||
|
sb.Append(hasQuery ? '&' : '?');
|
||||||
|
sb.Append(Uri.EscapeDataString(parameter.Key));
|
||||||
|
sb.Append('=');
|
||||||
|
sb.Append(Uri.EscapeDataString(parameter.Value));
|
||||||
|
hasQuery = true;
|
||||||
|
}
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue