Object.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // System.Object.cs
  3. //
  4. // Author:
  5. // Miguel de Icaza ([email protected])
  6. //
  7. // (C) Ximian, Inc. http://www.ximian.com
  8. //
  9. // This should probably be implemented in IL instead of C#, to
  10. // use internalcalls to get its hands on the underlying Type
  11. // of an object.
  12. //
  13. using System.Runtime.CompilerServices;
  14. namespace System {
  15. public class Object {
  16. // <summary>
  17. // Compares this object to the specified object.
  18. // Returns true if they are equal, false otherwise.
  19. // </summary>
  20. public virtual bool Equals (object o)
  21. {
  22. return this == o;
  23. }
  24. // <summary>
  25. // Compares two objects for equality
  26. // </summary>
  27. public static bool Equals (object a, object b)
  28. {
  29. if (a == b)
  30. return true;
  31. if (a == null) {
  32. if (b == null)
  33. return true;
  34. return false;
  35. } else {
  36. if (b == null)
  37. return false;
  38. return a.Equals (b);
  39. }
  40. }
  41. // <summary>
  42. // Initializes a new instance of the object class.
  43. // </summary>
  44. public Object ()
  45. {
  46. }
  47. // <summary>
  48. // Object destructor.
  49. // </summary>
  50. ~Object ()
  51. {
  52. }
  53. // <summary>
  54. // Returns a hashcode for this object. Each derived
  55. // class should return a hash code that makes sense
  56. // for that particular implementation of the object.
  57. // </summary>
  58. public virtual int GetHashCode ()
  59. {
  60. return 0;
  61. }
  62. // <summary>
  63. // Returns the Type associated with the object.
  64. // </summary>
  65. public Type GetType ()
  66. {
  67. // TODO: This probably needs to be tied up
  68. // with the Type system. Private communications
  69. // channel?
  70. // Type is abstract, so the following line won't cut it.
  71. //return new Type ();
  72. return null;
  73. }
  74. // <summary>
  75. // Shallow copy of the object.
  76. // </summary>
  77. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  78. protected extern object MemberwiseClone ();
  79. // <summary>
  80. // Returns a stringified representation of the object.
  81. // This is not supposed to be used for user presentation,
  82. // use Format() for that and IFormattable.
  83. //
  84. // ToString is mostly used for debugging purposes.
  85. // </summary>
  86. public virtual string ToString ()
  87. {
  88. return GetType().FullName;
  89. }
  90. // <summary>
  91. // Tests whether a is equal to b.
  92. // Can not figure out why this even exists
  93. // </summary>
  94. public static bool ReferenceEquals (object a, object b)
  95. {
  96. return (a == b);
  97. }
  98. }
  99. }