blob: 1bc1b738412d50d90c0ce9ffc7344308241ab66d (
plain)
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
|
using System.Collections.Generic;
namespace System.Web.Mvc
{
internal static class ValueProviderUtil
{
public static bool CollectionContainsPrefix(IEnumerable<string> collection, string prefix)
{
foreach (string key in collection)
{
if (key != null)
{
if (prefix.Length == 0)
{
return true; // shortcut - non-null key matches empty prefix
}
if (key.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
{
if (key.Length == prefix.Length)
{
return true; // exact match
}
else
{
switch (key[prefix.Length])
{
case '.': // known separator characters
case '[':
return true;
}
}
}
}
}
return false; // nothing found
}
}
}
|