forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompositeValueProvider.cs
More file actions
89 lines (80 loc) · 2.9 KB
/
Copy pathCompositeValueProvider.cs
File metadata and controls
89 lines (80 loc) · 2.9 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// 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.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
namespace System.Web.Http.ValueProviders.Providers
{
[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix", Justification = "It is more fundamentally a value provider than a collection")]
public class CompositeValueProvider : Collection<IValueProvider>, IValueProvider, IEnumerableValueProvider
{
public CompositeValueProvider()
{
}
public CompositeValueProvider(IList<IValueProvider> list)
: base(list)
{
}
public virtual bool ContainsPrefix(string prefix)
{
foreach (IValueProvider vp in this)
{
if (vp.ContainsPrefix(prefix))
{
return true;
}
}
return false;
}
public virtual ValueProviderResult GetValue(string key)
{
// Performance-sensitive
// Caching the count is faster for IList<T>
int itemCount = Items.Count;
for (int i = 0; i < itemCount; i++)
{
IValueProvider vp = Items[i];
ValueProviderResult result = vp.GetValue(key);
if (result != null)
{
return result;
}
}
return null;
}
public virtual IDictionary<string, string> GetKeysFromPrefix(string prefix)
{
foreach (IValueProvider vp in this)
{
IDictionary<string, string> result = GetKeysFromPrefixFromProvider(vp, prefix);
if (result != null && result.Count > 0)
{
return result;
}
}
return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
}
internal static IDictionary<string, string> GetKeysFromPrefixFromProvider(IValueProvider provider, string prefix)
{
IEnumerableValueProvider enumeratedProvider = provider as IEnumerableValueProvider;
return (enumeratedProvider != null) ? enumeratedProvider.GetKeysFromPrefix(prefix) : null;
}
protected override void InsertItem(int index, IValueProvider item)
{
if (item == null)
{
throw Error.ArgumentNull("item");
}
base.InsertItem(index, item);
}
protected override void SetItem(int index, IValueProvider item)
{
if (item == null)
{
throw Error.ArgumentNull("item");
}
base.SetItem(index, item);
}
}
}