MarshalByValueComponent.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // System.ComponentModel.MarshalByValueComponent.cs
  3. //
  4. // Author:
  5. // Rodrigo Moya ([email protected])
  6. // Andreas Nahr ([email protected])
  7. //
  8. // (C) Ximian, Inc
  9. // (C) 2003 Andreas Nahr
  10. //
  11. using System;
  12. using System.ComponentModel;
  13. using System.ComponentModel.Design;
  14. namespace System.ComponentModel
  15. {
  16. /// <summary>
  17. /// Implements IComponent and provides the base implementation for remotable components that are marshaled by value (a copy of the serialized object is passed).
  18. /// </summary>
  19. [DesignerCategory ("Component"),
  20. TypeConverter (typeof (ComponentConverter)),
  21. Designer ("System.Windows.Forms.Design.ComponentDocumentDesigner, System.Design, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof (IRootDesigner))]
  22. public class MarshalByValueComponent : IComponent, IDisposable, IServiceProvider
  23. {
  24. private EventHandlerList eventList;
  25. private ISite mySite;
  26. private object disposedEvent = new object ();
  27. public MarshalByValueComponent ()
  28. {
  29. }
  30. public void Dispose ()
  31. {
  32. Dispose (true);
  33. GC.SuppressFinalize (this);
  34. }
  35. [MonoTODO]
  36. protected virtual void Dispose (bool disposing)
  37. {
  38. if (disposing) {
  39. // free managed objects contained here
  40. }
  41. // Free unmanaged objects
  42. // Set fields to null
  43. }
  44. ~MarshalByValueComponent ()
  45. {
  46. Dispose (false);
  47. }
  48. [MonoTODO]
  49. public virtual object GetService (Type service) {
  50. return null;
  51. }
  52. [Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  53. public virtual IContainer Container {
  54. get {
  55. if (mySite == null)
  56. return null;
  57. return mySite.Container;
  58. }
  59. }
  60. [Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  61. public virtual bool DesignMode {
  62. get {
  63. if (mySite == null)
  64. return false;
  65. return mySite.DesignMode;
  66. }
  67. }
  68. [Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  69. public virtual ISite Site {
  70. get { return mySite; }
  71. set { mySite = value; }
  72. }
  73. public override string ToString ()
  74. {
  75. if (mySite == null)
  76. return GetType ().ToString ();
  77. return String.Format ("{0} [{1}]", mySite.Name, GetType ().ToString ());
  78. }
  79. protected EventHandlerList Events {
  80. get {
  81. if (eventList == null)
  82. eventList = new EventHandlerList ();
  83. return eventList;
  84. }
  85. }
  86. public event EventHandler Disposed
  87. {
  88. add { Events.AddHandler (disposedEvent, value); }
  89. remove { Events.RemoveHandler (disposedEvent, value); }
  90. }
  91. }
  92. }