CommandConfigCollection.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. /// Command configuration collection
  10. /// </summary>
  11. [ConfigurationCollection(typeof(CommandConfig))]
  12. public class CommandConfigCollection : ConfigurationElementCollection
  13. {
  14. /// <summary>
  15. /// Gets or sets a property, attribute, or child element of this configuration element.
  16. /// </summary>
  17. /// <returns>The specified property, attribute, or child element</returns>
  18. public CommandConfig this[int index]
  19. {
  20. get
  21. {
  22. return (CommandConfig)base.BaseGet(index);
  23. }
  24. set
  25. {
  26. if (base.BaseGet(index) != null)
  27. {
  28. base.BaseRemoveAt(index);
  29. }
  30. this.BaseAdd(index, value);
  31. }
  32. }
  33. /// <summary>
  34. /// When overridden in a derived class, creates a new <see cref="T:System.Configuration.ConfigurationElement"/>.
  35. /// </summary>
  36. /// <returns>
  37. /// A new <see cref="T:System.Configuration.ConfigurationElement"/>.
  38. /// </returns>
  39. protected override ConfigurationElement CreateNewElement()
  40. {
  41. return new CommandConfig();
  42. }
  43. /// <summary>
  44. /// Gets the element key for a specified configuration element when overridden in a derived class.
  45. /// </summary>
  46. /// <param name="element">The <see cref="T:System.Configuration.ConfigurationElement"/> to return the key for.</param>
  47. /// <returns>
  48. /// An <see cref="T:System.Object"/> that acts as the key for the specified <see cref="T:System.Configuration.ConfigurationElement"/>.
  49. /// </returns>
  50. protected override object GetElementKey(ConfigurationElement element)
  51. {
  52. return element.GetHashCode();
  53. }
  54. /// <summary>
  55. /// Gets the enumerator.
  56. /// </summary>
  57. /// <returns></returns>
  58. public new IEnumerator<CommandConfig> GetEnumerator()
  59. {
  60. int count = base.Count;
  61. for (int i = 0; i < count; i++)
  62. {
  63. yield return (CommandConfig)base.BaseGet(i);
  64. }
  65. }
  66. }
  67. }