Container.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. //
  2. // System.ComponentModel.Container.cs
  3. //
  4. // Author:
  5. // Miguel de Icaza ([email protected])
  6. //
  7. // (C) Ximian, Inc. http://www.ximian.com
  8. //
  9. namespace System.ComponentModel {
  10. // <summary>
  11. // Container class: encapsulates components.
  12. // </summary>
  13. //
  14. // <remarks>
  15. //
  16. // </remarks>
  17. public class Container : IContainer, IDisposable {
  18. ComponentCollection cc;
  19. // <summary>
  20. // Auxiliary class to support the default behaviour of CreateSite
  21. // </summary>
  22. //
  23. // <remarks>
  24. // This is an internal class that is used to provide a
  25. // default implementation of an ISite class. Container
  26. // is just a default implementation of IContainer, and
  27. // provides this as a way of getting started
  28. // </remarks>
  29. class DefaultSite : ISite {
  30. IComponent component;
  31. IContainer container;
  32. string name;
  33. public DefaultSite (string name, IComponent component, IContainer container)
  34. {
  35. this.component = component;
  36. this.container = container;
  37. this.name = name;
  38. }
  39. public IComponent Component {
  40. get {
  41. return component;
  42. }
  43. }
  44. public IContainer Container {
  45. get {
  46. return container;
  47. }
  48. }
  49. [MonoTODO]
  50. public bool DesignMode {
  51. get {
  52. // FIXME: should we provide a way to set
  53. // this value?
  54. return false;
  55. }
  56. }
  57. public string Name {
  58. get {
  59. return name;
  60. }
  61. set {
  62. name = value;
  63. }
  64. }
  65. [MonoTODO]
  66. public virtual object GetService (Type t)
  67. {
  68. // FIXME: do not know what this is supposed to do.
  69. return null;
  70. }
  71. }
  72. // <summary>
  73. // Container constructor
  74. // </summary>
  75. public Container ()
  76. {
  77. }
  78. public virtual ComponentCollection Components {
  79. get {
  80. return cc;
  81. }
  82. }
  83. // <summary>
  84. // Adds an IComponent to the Container
  85. // </summary>
  86. [MonoTODO]
  87. public virtual void Add (IComponent component)
  88. {
  89. // FIXME: Add this component to the ComponentCollection.cc
  90. }
  91. // <summary>
  92. // Adds an IComponent to the Container. With a name binding.
  93. // </summary>
  94. [MonoTODO]
  95. public virtual void Add (IComponent component, string name)
  96. {
  97. // FIXME: Add this component to the ComponentCollection.cc
  98. }
  99. // <summary>
  100. // Returns an ISite for a component.
  101. // <summary>
  102. protected virtual ISite CreateSite (IComponent component, string name)
  103. {
  104. return new DefaultSite (name, component, this);
  105. }
  106. public void Dispose ()
  107. {
  108. Dispose (true);
  109. GC.SuppressFinalize (this);
  110. }
  111. bool disposed = false;
  112. protected virtual void Dispose (bool release_all)
  113. {
  114. if (disposed)
  115. return;
  116. if (release_all){
  117. cc.Dispose ();
  118. cc = null;
  119. }
  120. disposed = true;
  121. }
  122. [MonoTODO]
  123. protected virtual object GetService (Type service)
  124. {
  125. // FIXME: Not clear what GetService does.
  126. return null;
  127. }
  128. [MonoTODO]
  129. public virtual void Remove (IComponent component)
  130. {
  131. // FIXME: Add this component to the ComponentCollection.cc
  132. }
  133. }
  134. }