MarshalByValueComponent.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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"), TypeConverter (typeof (ComponentConverter))]
  20. [Designer ("System.Windows.Forms.Design.ComponentDocumentDesigner, " + Consts.AssemblySystem_Design, typeof (IRootDesigner))]
  21. public class MarshalByValueComponent : IComponent, IDisposable, IServiceProvider
  22. {
  23. private EventHandlerList eventList;
  24. private ISite mySite;
  25. private object disposedEvent = new object ();
  26. public MarshalByValueComponent ()
  27. {
  28. }
  29. public void Dispose ()
  30. {
  31. Dispose (true);
  32. GC.SuppressFinalize (this);
  33. }
  34. [MonoTODO]
  35. protected virtual void Dispose (bool disposing)
  36. {
  37. if (disposing) {
  38. // free managed objects contained here
  39. }
  40. // Free unmanaged objects
  41. // Set fields to null
  42. }
  43. ~MarshalByValueComponent ()
  44. {
  45. Dispose (false);
  46. }
  47. public virtual object GetService (Type service)
  48. {
  49. if (mySite != null) {
  50. return mySite.GetService(service);
  51. }
  52. return null;
  53. }
  54. [Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  55. public virtual IContainer Container {
  56. get {
  57. if (mySite == null)
  58. return null;
  59. return mySite.Container;
  60. }
  61. }
  62. [Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  63. public virtual bool DesignMode {
  64. get {
  65. if (mySite == null)
  66. return false;
  67. return mySite.DesignMode;
  68. }
  69. }
  70. [Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  71. public virtual ISite Site {
  72. get { return mySite; }
  73. set { mySite = value; }
  74. }
  75. public override string ToString ()
  76. {
  77. if (mySite == null)
  78. return GetType ().ToString ();
  79. return String.Format ("{0} [{1}]", mySite.Name, GetType ().ToString ());
  80. }
  81. protected EventHandlerList Events {
  82. get {
  83. if (eventList == null)
  84. eventList = new EventHandlerList ();
  85. return eventList;
  86. }
  87. }
  88. public event EventHandler Disposed
  89. {
  90. add { Events.AddHandler (disposedEvent, value); }
  91. remove { Events.RemoveHandler (disposedEvent, value); }
  92. }
  93. }
  94. }