1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
5 using System
.Reflection
;
6 using System
.Runtime
.CompilerServices
;
11 [System
.Runtime
.CompilerServices
.TypeForwardedFrom ("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
12 public abstract class ValueType
14 // This is also used by RuntimeHelpers
15 internal static bool DefaultEquals (object o1
, object o2
)
17 RuntimeType o1_type
= (RuntimeType
) o1
.GetType ();
18 RuntimeType o2_type
= (RuntimeType
) o2
.GetType ();
20 if (o1_type
!= o2_type
)
24 bool res
= InternalEquals (o1
, o2
, out fields
);
28 for (int i
= 0; i
< fields
.Length
; i
+= 2) {
29 object meVal
= fields
[i
];
30 object youVal
= fields
[i
+ 1];
38 if (!meVal
.Equals (youVal
))
45 public override bool Equals (object? obj
)
50 return DefaultEquals (this, obj
);
53 public override int GetHashCode ()
55 int result
= InternalGetHashCode (this, out var fields
);
58 for (int i
= 0; i
< fields
.Length
; ++i
)
59 if (fields
[i
] != null)
60 result ^
= fields
[i
].GetHashCode ();
65 public override string ToString ()
67 return GetType ().ToString ();
71 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
72 extern static int InternalGetHashCode (object o
, out object[]? fields
);
74 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
75 extern static bool InternalEquals (object o1
, object o2
, out object[] fields
);