1 namespace System.Web.Mvc {
3 using System.Collections.Generic;
6 internal static class DictionaryHelpers {
8 public static IEnumerable<KeyValuePair<string, TValue>> FindKeysWithPrefix<TValue>(IDictionary<string, TValue> dictionary, string prefix) {
9 TValue exactMatchValue;
10 if (dictionary.TryGetValue(prefix, out exactMatchValue)) {
11 yield return new KeyValuePair<string, TValue>(prefix, exactMatchValue);
14 foreach (var entry in dictionary) {
15 string key = entry.Key;
17 if (key.Length <= prefix.Length) {
21 if (!key.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)) {
25 char charAfterPrefix = key[prefix.Length];
26 switch (charAfterPrefix) {
35 public static bool DoesAnyKeyHavePrefix<TValue>(IDictionary<string, TValue> dictionary, string prefix) {
36 return FindKeysWithPrefix(dictionary, prefix).Any();