SubProtocolConfigCollection.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Configuration;
  6. namespace SuperWebSocket.Config
  7. {
  8. /// <summary>
  9. /// SubProtocol configuation collection
  10. /// </summary>
  11. [ConfigurationCollection(typeof(SubProtocolConfig))]
  12. public class SubProtocolConfigCollection : ConfigurationElementCollection
  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 SubProtocolConfig();
  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. return ((SubProtocolConfig)element).Name;
  34. }
  35. /// <summary>
  36. /// Gets the enumerator.
  37. /// </summary>
  38. /// <returns></returns>
  39. public new IEnumerator<SubProtocolConfig> GetEnumerator()
  40. {
  41. int count = base.Count;
  42. for (int i = 0; i < count; i++)
  43. {
  44. yield return (SubProtocolConfig)base.BaseGet(i);
  45. }
  46. }
  47. /// <summary>
  48. /// Gets the type of the <see cref="T:System.Configuration.ConfigurationElementCollection"/>.
  49. /// </summary>
  50. /// <returns>The <see cref="T:System.Configuration.ConfigurationElementCollectionType"/> of this collection.</returns>
  51. public override ConfigurationElementCollectionType CollectionType
  52. {
  53. get
  54. {
  55. return ConfigurationElementCollectionType.BasicMap;
  56. }
  57. }
  58. /// <summary>
  59. /// Gets the name used to identify this collection of elements in the configuration file when overridden in a derived class.
  60. /// </summary>
  61. /// <returns>The name of the collection; otherwise, an empty string. The default is an empty string.</returns>
  62. protected override string ElementName
  63. {
  64. get
  65. {
  66. return "protocol";
  67. }
  68. }
  69. }
  70. }