Component.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. [MonoTODO]
  65. ~Component()
  66. {
  67. // FIXME: Not sure this is correct.
  68. Dispose(true);
  69. Disposed(this, EventArgs.Empty);
  70. }
  71. // <summary>
  72. // Dispose resources used by this component
  73. // </summary>
  74. [MonoTODO]
  75. public virtual void Dispose ()
  76. {
  77. // FIXME: Not sure this is correct.
  78. Dispose(false);
  79. Disposed(this, EventArgs.Empty);
  80. }
  81. // <summary>
  82. // Controls disposal of resources used by this.
  83. // </summary>
  84. //
  85. // <param name="release_all"> Controls which resources are released</param>
  86. //
  87. // <remarks>
  88. // if release_all is set to true, both managed and unmanaged
  89. // resources should be released. If release_all is set to false,
  90. // only unmanaged resources should be disposed
  91. // </remarks>
  92. protected virtual void Dispose (bool release_all)
  93. {
  94. }
  95. // <summary>
  96. // Implements the IServiceProvider interface
  97. // </summary>
  98. [MonoTODO]
  99. protected virtual object GetService (Type service)
  100. {
  101. // FIXME: Not sure what this should do.
  102. return null;
  103. }
  104. // <summary>
  105. // FIXME: Figure out this one.
  106. // </summary>
  107. [MonoTODO ("Figure this out")]
  108. public event EventHandler Disposed;
  109. }
  110. }