forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDictionaryExtensions.cs
More file actions
33 lines (29 loc) · 1007 Bytes
/
DictionaryExtensions.cs
File metadata and controls
33 lines (29 loc) · 1007 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#if !SILVERLIGHT && !MONOTOUCH && !XBOX
using System.Collections.Generic;
using System.Collections.Specialized;
namespace ServiceStack.ServiceModel.Extensions
{
public static class DictionaryExtensions
{
public static Dictionary<string, string> ToDictionary(this NameValueCollection nameValues)
{
var map = new Dictionary<string, string>();
foreach (var key in nameValues.AllKeys)
{
if (key == null)
{
//occurs when no value is specified, e.g. 'path/to/page?debug'
//throw new ArgumentNullException("key", "nameValues: " + nameValues);
continue;
}
var values = nameValues.GetValues(key);
if (values != null && values.Length > 0)
{
map[key] = values[0];
}
}
return map;
}
}
}
#endif