1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- using System;
- using System.Configuration;
- using System.Collections.Generic;
- namespace SuperSocket.Common
- {
-
-
-
-
-
- public class GenericConfigurationElementCollectionBase<TConfigElement, TConfigInterface> : ConfigurationElementCollection, IEnumerable<TConfigInterface>
- where TConfigElement : ConfigurationElement, TConfigInterface, new()
- {
-
-
-
-
- public TConfigElement this[int index]
- {
- get
- {
- return (TConfigElement)base.BaseGet(index);
- }
- set
- {
- if (base.BaseGet(index) != null)
- {
- base.BaseRemoveAt(index);
- }
- this.BaseAdd(index, value as ConfigurationElement);
- }
- }
-
-
-
-
-
-
- protected override ConfigurationElement CreateNewElement()
- {
- return new TConfigElement() as ConfigurationElement;
- }
-
-
-
-
-
-
-
- protected override object GetElementKey(ConfigurationElement element)
- {
- return element;
- }
- #region IEnumerable[T] implementation
-
-
-
-
-
-
- public new IEnumerator<TConfigInterface> GetEnumerator()
- {
- int count = base.Count;
- for (int i = 0; i < count; i++)
- {
- yield return (TConfigElement)base.BaseGet(i);
- }
- }
- #endregion
- }
-
-
-
-
-
- public class GenericConfigurationElementCollection<TConfigElement, TConfigInterface> : GenericConfigurationElementCollectionBase<TConfigElement, TConfigInterface>, IEnumerable<TConfigInterface>
- where TConfigElement : ConfigurationElementBase, TConfigInterface, new()
- {
-
-
-
-
-
- protected override object GetElementKey(ConfigurationElement element)
- {
- return ((TConfigElement)element).Name;
- }
- }
- }
|