Blog de Francisco Velázquez

otro blog personal

Helper para ConfigurationElementCollection

leave a comment »

Interesante utilidad que ayuda muchísimo para trabajar con colecciones en archivos de configuración.

    public class ConfigurationElementCollection<T> :
        ConfigurationElementCollection, IEnumerable<T> where T : ConfigurationElement, new()
        protected override ConfigurationElement CreateNewElement()
            return new T();
        protected override object GetElementKey(ConfigurationElement element)
            return ((T)(element)).ToString();
        public T this[int idx]
            get { return (T)BaseGet(idx); }

        public new IEnumerator<T> GetEnumerator()
            int count = base.Count;
            for (int i = 0; i < count; i++)
                yield return base.BaseGet(i) as T;

Written by fravelgue

September 6, 2011 at 4:41 pm

Posted in development

Tagged with , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: