Container.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. public bool DesignMode {
  50. get {
  51. // FIXME: should we provide a way to set
  52. // this value?
  53. return false;
  54. }
  55. }
  56. public string Name {
  57. get {
  58. return name;
  59. }
  60. set {
  61. name = value;
  62. }
  63. }
  64. public virtual object GetService (Type t)
  65. {
  66. // FIXME: do not know what this is supposed to do.
  67. return null;
  68. }
  69. }
  70. // <summary>
  71. // Container constructor
  72. // </summary>
  73. public Container ()
  74. {
  75. }
  76. public virtual ComponentCollection Components {
  77. get {
  78. return cc;
  79. }
  80. }
  81. // <summary>
  82. // Adds an IComponent to the Container
  83. // </summary>
  84. public virtual void Add (IComponent component)
  85. {
  86. // FIXME: Add this component to the ComponentCollection.cc
  87. }
  88. // <summary>
  89. // Adds an IComponent to the Container. With a name binding.
  90. // </summary>
  91. public virtual void Add (IComponent component, string name)
  92. {
  93. // FIXME: Add this component to the ComponentCollection.cc
  94. }
  95. // <summary>
  96. // Returns an ISite for a component.
  97. // <summary>
  98. protected virtual ISite CreateSite (IComponent component, string name)
  99. {
  100. return new DefaultSite (name, component, this);
  101. }
  102. public virtual void Dispose ()
  103. {
  104. Dispose (true);
  105. GC.SuppressFinalize (this);
  106. }
  107. bool disposed = false;
  108. public virtual void Dispose (bool release_all)
  109. {
  110. if (disposed)
  111. return;
  112. if (release_all){
  113. cc.Dispose ();
  114. cc = null;
  115. }
  116. disposed = true;
  117. }
  118. protected virtual object GetService (Type service)
  119. {
  120. // FIXME: Not clear what GetService does.
  121. return null;
  122. }
  123. public virtual void Remove (IComponent component)
  124. {
  125. // FIXME: Add this component to the ComponentCollection.cc
  126. }
  127. }
  128. }