Component.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // System.ComponentModel.Component.cs
  3. //
  4. // Author:
  5. // Miguel de Icaza ([email protected])
  6. //
  7. // (C) Ximian, Inc. http://www.ximian.com
  8. //
  9. using System;
  10. namespace System.ComponentModel {
  11. // <summary>
  12. // Component class.
  13. // </summary>
  14. //
  15. // <remarks>
  16. // Longer description
  17. // </remarks>
  18. public class Component : MarshalByRefObject, IComponent, IDisposable {
  19. EventHandlerList event_handlers;
  20. ISite mySite;
  21. // <summary>
  22. // Component Constructor
  23. // </summary>
  24. public Component ()
  25. {
  26. event_handlers = null;
  27. }
  28. // <summary>
  29. // Get IContainer of this Component
  30. // </summary>
  31. public IContainer Container {
  32. get {
  33. return mySite.Container;
  34. }
  35. }
  36. protected bool DesignMode {
  37. get {
  38. return mySite.DesignMode;
  39. }
  40. }
  41. protected EventHandlerList Events {
  42. get {
  43. // Note: space vs. time tradeoff
  44. // We create the object here if it's never be accessed before. This potentially
  45. // saves space. However, we must check each time the propery is accessed to
  46. // determine whether we need to create the object, which increases overhead.
  47. // We could put the creation in the contructor, but that would waste space
  48. // if it were never used. However, accessing this property would be faster.
  49. if (null == event_handlers)
  50. {
  51. event_handlers = new EventHandlerList();
  52. }
  53. return event_handlers;
  54. }
  55. }
  56. public virtual ISite Site {
  57. get {
  58. return mySite;
  59. }
  60. set {
  61. mySite = value;
  62. }
  63. }
  64. ~Component()
  65. {
  66. // FIXME: Not sure this is correct.
  67. Dispose(true);
  68. Disposed(this, EventArgs.Empty);
  69. }
  70. // <summary>
  71. // Dispose resources used by this component
  72. // </summary>
  73. public virtual void Dispose ()
  74. {
  75. // FIXME: Not sure this is correct.
  76. Dispose(false);
  77. Disposed(this, EventArgs.Empty);
  78. }
  79. // <summary>
  80. // Controls disposal of resources used by this.
  81. // </summary>
  82. //
  83. // <param name="release_all"> Controls which resources are released</param>
  84. //
  85. // <remarks>
  86. // if release_all is set to true, both managed and unmanaged
  87. // resources should be released. If release_all is set to false,
  88. // only unmanaged resources should be disposed
  89. // </remarks>
  90. protected virtual void Dispose (bool release_all)
  91. {
  92. }
  93. // <summary>
  94. // Implements the IServiceProvider interface
  95. // </summary>
  96. protected virtual object GetService (Type service)
  97. {
  98. // FIXME: Not sure what this should do.
  99. return null;
  100. }
  101. // <summary>
  102. // FIXME: Figure out this one.
  103. // </summary>
  104. public event EventHandler Disposed;
  105. }
  106. }