forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDictionaryValueProvider.cs
More file actions
64 lines (55 loc) · 2.13 KB
/
Copy pathDictionaryValueProvider.cs
File metadata and controls
64 lines (55 loc) · 2.13 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Globalization;
namespace System.Web.Mvc
{
public class DictionaryValueProvider<TValue> : IValueProvider, IEnumerableValueProvider
{
private PrefixContainer _prefixContainer;
private readonly Dictionary<string, ValueProviderResult> _values = new Dictionary<string, ValueProviderResult>(StringComparer.OrdinalIgnoreCase);
public DictionaryValueProvider(IDictionary<string, TValue> dictionary, CultureInfo culture)
{
if (dictionary == null)
{
throw new ArgumentNullException("dictionary");
}
foreach (KeyValuePair<string, TValue> entry in dictionary)
{
object rawValue = entry.Value;
string attemptedValue = Convert.ToString(rawValue, culture);
_values[entry.Key] = new ValueProviderResult(rawValue, attemptedValue, culture);
}
}
private PrefixContainer PrefixContainer
{
get
{
if (_prefixContainer == null)
{
// Race condition on initialization has no side effects
_prefixContainer = new PrefixContainer(_values.Keys);
}
return _prefixContainer;
}
}
public virtual bool ContainsPrefix(string prefix)
{
return PrefixContainer.ContainsPrefix(prefix);
}
public virtual ValueProviderResult GetValue(string key)
{
if (key == null)
{
throw new ArgumentNullException("key");
}
ValueProviderResult valueProviderResult;
_values.TryGetValue(key, out valueProviderResult);
return valueProviderResult;
}
public virtual IDictionary<string, string> GetKeysFromPrefix(string prefix)
{
return PrefixContainer.GetKeysFromPrefix(prefix);
}
}
}