Container.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. void DefaultSite (string name, IComponent component, IContainer container)
  34. {
  35. this.component = component;
  36. this.container = container;
  37. this.name = name;
  38. }
  39. IComponent Component {
  40. get {
  41. return component;
  42. }
  43. }
  44. IContainer Container {
  45. get {
  46. return container;
  47. }
  48. }
  49. bool DesignMode {
  50. get {
  51. // FIXME: should we provide a way to set
  52. // this value?
  53. return false;
  54. }
  55. }
  56. string Name {
  57. get {
  58. return name;
  59. }
  60. }
  61. }
  62. // <summary>
  63. // Container constructor
  64. // </summary>
  65. public Container ()
  66. {
  67. }
  68. public virtual ComponentCollection Components {
  69. get {
  70. return cc;
  71. }
  72. }
  73. // <summary>
  74. // Adds an IComponent to the Container
  75. // </summary>
  76. public virtual void Add (IComponent component)
  77. {
  78. // FIXME: Add this component to the ComponentCollection.cc
  79. }
  80. // <summary>
  81. // Adds an IComponent to the Container. With a name binding.
  82. // </summary>
  83. public virtual void Add (IComponent component, string name)
  84. {
  85. // FIXME: Add this component to the ComponentCollection.cc
  86. }
  87. // <summary>
  88. // Returns an ISite for a component.
  89. // <summary>
  90. protected virtual ISite CreateSite (IComponent component, string name)
  91. {
  92. return DefaultSite (name, component, this);
  93. }
  94. public virtual void Dispose ()
  95. {
  96. Dispose (true);
  97. GC.SupressFinalize (this);
  98. }
  99. bool disposed = false;
  100. public virtual void Dispose (bool release_all)
  101. {
  102. if (disposed)
  103. return;
  104. if (release_all){
  105. cc.Dispose ();
  106. cc = null;
  107. }
  108. disposed = true;
  109. }
  110. protected virtual object GetService (Type service)
  111. {
  112. // FIXME: Not clear what GetService does.
  113. return null;
  114. }
  115. public virtual void Remove (IComponent component)
  116. {
  117. // FIXME: Add this component to the ComponentCollection.cc
  118. }
  119. }
  120. }