2002-01-14 Miguel de Icaza <miguel@ximian.com>
[mono.git] / mcs / class / corlib / System / Object.cs
1 //
2 // System.Object.cs
3 //
4 // Author:
5 //   Miguel de Icaza (miguel@ximian.com)
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
14 using System.Runtime.CompilerServices;
15
16 namespace System {
17
18         public class Object {
19
20                 // <summary>
21                 //   Compares this object to the specified object.
22                 //   Returns true if they are equal, false otherwise.
23                 // </summary>
24                 public virtual bool Equals (object o)
25                 {
26                         return this == o;
27                 }
28
29                 // <summary>
30                 //   Compares two objects for equality
31                 // </summary>
32                 public static bool Equals (object a, object b)
33                 {
34                         if (a == b)
35                                 return true;
36                         
37                         if (a == null) {
38                                 if (b == null)
39                                         return true;
40                                 return false;
41                         } else {
42                                 if (b == null)
43                                         return false;
44                                 return a.Equals (b);
45                         }
46                 }
47
48                 // <summary>
49                 //   Initializes a new instance of the object class.
50                 // </summary>
51                 public Object ()
52                 {
53                 }
54
55                 // <summary>
56                 //   Object destructor. 
57                 // </summary>
58                 ~Object ()
59                 {
60                 }
61
62                 // <summary>
63                 //   Returns a hashcode for this object.  Each derived
64                 //   class should return a hash code that makes sense
65                 //   for that particular implementation of the object.
66                 // </summary>
67                 public virtual int GetHashCode ()
68                 {
69                         return 0;
70                 }
71
72                 // <summary>
73                 //   Returns the Type associated with the object.
74                 // </summary>
75                 public Type GetType ()
76                 {
77                         return new MonoType (this);
78                 }
79
80                 // <summary>
81                 //   Shallow copy of the object.
82                 // </summary>
83                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
84                 protected extern object MemberwiseClone ();
85
86                 // <summary>
87                 //   Returns a stringified representation of the object.
88                 //   This is not supposed to be used for user presentation,
89                 //   use Format() for that and IFormattable.
90                 //
91                 //   ToString is mostly used for debugging purposes. 
92                 // </summary>
93                 public virtual string ToString ()
94                 {
95                         return GetType().FullName;
96                 }
97
98                 // <summary>
99                 //   Tests whether a is equal to b.
100                 //   Can not figure out why this even exists
101                 // </summary>
102                 public static bool ReferenceEquals (object a, object b)
103                 {
104                         return (a == b);
105                 }
106         }
107 }