using System; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Text; namespace Umbraco.Core { internal static class NameValueCollectionExtensions { public static IEnumerable> AsEnumerable(this NameValueCollection nvc) { foreach (string key in nvc.AllKeys) { yield return new KeyValuePair(key, nvc[key]); } } public static bool ContainsKey(this NameValueCollection collection, string key) { return collection.Keys.Cast().Any(k => (string) k == key); } public static T GetValue(this NameValueCollection collection, string key, T defaultIfNotFound) { if (collection.ContainsKey(key) == false) { return defaultIfNotFound; } var val = collection[key]; if (val == null) { return defaultIfNotFound; } var result = val.TryConvertTo(); return result.Success ? result.Result : defaultIfNotFound; } } }