Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Commit 1aed739

Browse files
committed
WebUtilities: Add more query helpers.
1 parent bc0732f commit 1aed739

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/Microsoft.AspNet.WebUtilities/FormHelpers.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using System;
1+
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
25
using Microsoft.AspNet.Http;
36

47
namespace Microsoft.AspNet.WebUtilities

src/Microsoft.AspNet.WebUtilities/QueryHelpers.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
using System;
1+
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Text;
27

38
namespace Microsoft.AspNet.WebUtilities
49
{
@@ -16,5 +21,27 @@ public static string AddQueryString([NotNull] string uri, [NotNull] string name,
1621
bool hasQuery = uri.IndexOf('?') != -1;
1722
return uri + (hasQuery ? "&" : "?") + Uri.EscapeDataString(name) + "=" + Uri.EscapeDataString(value);
1823
}
24+
25+
/// <summary>
26+
/// Append the given query keys and values to the uri.
27+
/// </summary>
28+
/// <param name="uri">The base uri.</param>
29+
/// <param name="queryString">A collection of name value query pairs to append.</param>
30+
/// <returns>The combine result.</returns>
31+
public static string AddQueryString([NotNull] string uri, [NotNull] IDictionary<string, string> queryString)
32+
{
33+
var sb = new StringBuilder();
34+
sb.Append(uri);
35+
bool hasQuery = uri.IndexOf('?') != -1;
36+
foreach (var parameter in queryString)
37+
{
38+
sb.Append(hasQuery ? '&' : '?');
39+
sb.Append(Uri.EscapeDataString(parameter.Key));
40+
sb.Append('=');
41+
sb.Append(Uri.EscapeDataString(parameter.Value));
42+
hasQuery = true;
43+
}
44+
return sb.ToString();
45+
}
1946
}
2047
}

0 commit comments

Comments
 (0)