ServiceDescriptionBaseCollection.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // System.Web.Services.Description.ServiceDescriptionBaseCollection.cs
  3. //
  4. // Author:
  5. // Tim Coleman ([email protected])
  6. //
  7. // Copyright (C) Tim Coleman, 2002
  8. //
  9. using System.Collections;
  10. using System.Web.Services;
  11. namespace System.Web.Services.Description {
  12. public abstract class ServiceDescriptionBaseCollection : CollectionBase {
  13. #region Fields
  14. Hashtable table = new Hashtable ();
  15. object parent;
  16. #endregion // Fields
  17. #region Constructors
  18. internal ServiceDescriptionBaseCollection (object parent)
  19. {
  20. this.parent = parent;
  21. }
  22. #endregion // Constructors
  23. #region Properties
  24. protected virtual IDictionary Table {
  25. get { return table; }
  26. }
  27. #endregion // Properties
  28. #region Methods
  29. protected virtual string GetKey (object value)
  30. {
  31. return null;
  32. }
  33. protected override void OnClear ()
  34. {
  35. Table.Clear ();
  36. }
  37. protected override void OnInsertComplete (int index, object value)
  38. {
  39. if (GetKey (value) != null)
  40. Table [GetKey (value)] = value;
  41. SetParent (value, parent);
  42. }
  43. protected override void OnRemove (int index, object value)
  44. {
  45. if (GetKey (value) != null)
  46. Table.Remove (GetKey (value));
  47. }
  48. protected override void OnSet (int index, object oldValue, object newValue)
  49. {
  50. if (GetKey (oldValue) != null)
  51. Table.Remove (GetKey (oldValue));
  52. if (GetKey (newValue) != null)
  53. Table [GetKey (newValue)] = newValue;
  54. SetParent (newValue, parent);
  55. }
  56. protected virtual void SetParent (object value, object parent)
  57. {
  58. }
  59. #endregion // Methods
  60. }
  61. }