TypeProviderCollection.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Configuration;
  6. namespace SuperSocket.SocketBase.Config
  7. {
  8. /// <summary>
  9. /// Type provider colletion configuration
  10. /// </summary>
  11. [ConfigurationCollection(typeof(TypeProvider))]
  12. public class TypeProviderCollection : ConfigurationElementCollection, IEnumerable<ITypeProvider>
  13. {
  14. /// <summary>
  15. /// When overridden in a derived class, creates a new <see cref="T:System.Configuration.ConfigurationElement"/>.
  16. /// </summary>
  17. /// <returns>
  18. /// A new <see cref="T:System.Configuration.ConfigurationElement"/>.
  19. /// </returns>
  20. protected override ConfigurationElement CreateNewElement()
  21. {
  22. return new TypeProvider() as ConfigurationElement;
  23. }
  24. /// <summary>
  25. /// Gets the element key for a specified configuration element when overridden in a derived class.
  26. /// </summary>
  27. /// <param name="element">The <see cref="T:System.Configuration.ConfigurationElement"/> to return the key for.</param>
  28. /// <returns>
  29. /// An <see cref="T:System.Object"/> that acts as the key for the specified <see cref="T:System.Configuration.ConfigurationElement"/>.
  30. /// </returns>
  31. protected override object GetElementKey(ConfigurationElement element)
  32. {
  33. var provider = element as TypeProvider;
  34. if (provider == null)
  35. return null;
  36. return provider.Name;
  37. }
  38. /// <summary>
  39. /// Returns an enumerator that iterates through the collection.
  40. /// </summary>
  41. /// <returns>
  42. /// A <see cref="T:System.Collections.Generic.IEnumerator`1"/> that can be used to iterate through the collection.
  43. /// </returns>
  44. public new IEnumerator<ITypeProvider> GetEnumerator()
  45. {
  46. int count = base.Count;
  47. for (int i = 0; i < count; i++)
  48. {
  49. yield return (ITypeProvider)base.BaseGet(i);
  50. }
  51. }
  52. }
  53. }