5 // Miguel de Icaza (miguel@ximian.com)
6 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
8 // (C) Ximian, Inc. http://www.ximian.com
9 // (C) 2003 Novell, Inc. http://www.novell.com
12 using System.Reflection;
13 using System.Runtime.CompilerServices;
18 public abstract class ValueType
20 protected ValueType ()
24 [MethodImplAttribute (MethodImplOptions.InternalCall)]
25 internal extern static bool InternalEquals (object o1, object o2, out object[] fields);
27 // This is also used by RuntimeHelpers
28 internal static bool DefaultEquals (object o1, object o2)
35 bool res = InternalEquals (o1, o2, out fields);
39 for (int i = 0; i < fields.Length; i += 2) {
40 object meVal = fields [i];
41 object youVal = fields [i + 1];
49 if (!meVal.Equals (youVal))
57 // True if this instance and o represent the same type
58 // and have the same value.
60 public override bool Equals (object o) {
61 return DefaultEquals (this, o);
64 [MethodImplAttribute (MethodImplOptions.InternalCall)]
65 internal extern static int InternalGetHashCode (object o, out object[] fields);
68 // Gets a hashcode for this value type using the
69 // bits in the structure
71 public override int GetHashCode ()
74 int result = InternalGetHashCode (this, out fields);
77 for (int i = 0; i < fields.Length; ++i)
78 if (fields [i] != null)
79 result ^= fields [i].GetHashCode ();
85 // Stringified representation of this ValueType.
86 // Must be overriden for better results, by default
87 // it just returns the Type name.
89 public override string ToString ()
91 return GetType ().FullName;