using System; using System.Collections.Generic; using System.Configuration; using System.Linq; namespace Umbraco.Core.Configuration.HealthChecks { [ConfigurationCollection(typeof(NotificationMethodSettingsElement), AddItemName = "add")] public class NotificationMethodSettingsElementCollection : ConfigurationElementCollection, IEnumerable, IReadOnlyDictionary { protected override ConfigurationElement CreateNewElement() { return new NotificationMethodSettingsElement(); } protected override object GetElementKey(ConfigurationElement element) { return ((NotificationMethodSettingsElement)(element)).Key; } IEnumerator> IEnumerable>.GetEnumerator() { for (var i = 0; i < Count; i++) { var val = (NotificationMethodSettingsElement)BaseGet(i); var key = (string)BaseGetKey(i); yield return new KeyValuePair(key, val); } } IEnumerator IEnumerable.GetEnumerator() { for (var i = 0; i < Count; i++) { yield return (NotificationMethodSettingsElement)BaseGet(i); } } bool IReadOnlyDictionary.ContainsKey(string key) { return ((IReadOnlyDictionary)this).Keys.Any(x => x == key); } bool IReadOnlyDictionary.TryGetValue(string key, out INotificationMethodSettings value) { try { var val = (NotificationMethodSettingsElement)BaseGet(key); value = val; return true; } catch (Exception) { value = null; return false; } } INotificationMethodSettings IReadOnlyDictionary.this[string key] { get { return (NotificationMethodSettingsElement)BaseGet(key); } } IEnumerable IReadOnlyDictionary.Keys { get { return BaseGetAllKeys().Cast(); } } IEnumerable IReadOnlyDictionary.Values { get { for (var i = 0; i < Count; i++) { yield return (NotificationMethodSettingsElement)BaseGet(i); } } } } }