From fd2adccf3e921979d6716462f64d3b423d9cbf46 Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Fri, 21 Dec 2018 22:29:59 +0100 Subject: [PATCH] Moves common part of Object to CoreLib shared --- .../shared/System.Private.CoreLib.Shared.projitems | 1 + src/System.Private.CoreLib/shared/System/Object.cs | 85 ++++++++++++++++++++++ src/System.Private.CoreLib/src/System/Object.cs | 69 +----------------- 3 files changed, 87 insertions(+), 68 deletions(-) create mode 100644 src/System.Private.CoreLib/shared/System/Object.cs diff --git a/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems b/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems index 27d43b7..397853e 100644 --- a/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems +++ b/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems @@ -351,6 +351,7 @@ + diff --git a/src/System.Private.CoreLib/shared/System/Object.cs b/src/System.Private.CoreLib/shared/System/Object.cs new file mode 100644 index 0000000..0885c88 --- /dev/null +++ b/src/System.Private.CoreLib/shared/System/Object.cs @@ -0,0 +1,85 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Versioning; + +namespace System +{ + // The Object is the root class for all object in the CLR System. Object + // is the super class for all other CLR objects and provide a set of methods and low level + // services to subclasses. These services include object synchronization and support for clone + // operations. + // + [Serializable] + [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] + public partial class Object + { + // Creates a new instance of an Object. + [NonVersionable] + public Object() + { + } + + // Returns a String which represents the object instance. The default + // for an object is to return the fully qualified name of the class. + // + public virtual string ToString() + { + return GetType().ToString(); + } + + // Returns a boolean indicating if the passed in object obj is + // Equal to this. Equality is defined as object equality for reference + // types and bitwise equality for value types using a loader trick to + // replace Equals with EqualsValue for value types). + // + + public virtual bool Equals(object obj) + { + return RuntimeHelpers.Equals(this, obj); + } + + public static bool Equals(object objA, object objB) + { + if (objA == objB) + { + return true; + } + if (objA == null || objB == null) + { + return false; + } + return objA.Equals(objB); + } + + [NonVersionable] + public static bool ReferenceEquals(object objA, object objB) + { + return objA == objB; + } + + // GetHashCode is intended to serve as a hash function for this object. + // Based on the contents of the object, the hash function will return a suitable + // value with a relatively random distribution over the various inputs. + // + // The default implementation returns the sync block index for this instance. + // Calling it on the same object multiple times will return the same value, so + // it will technically meet the needs of a hash function, but it's less than ideal. + // Objects (& especially value classes) should override this method. + // + public virtual int GetHashCode() + { + return RuntimeHelpers.GetHashCode(this); + } + + // Allow an object to free resources before the object is reclaimed by the GC. + // + [NonVersionable] + ~Object() + { + } + } +} \ No newline at end of file diff --git a/src/System.Private.CoreLib/src/System/Object.cs b/src/System.Private.CoreLib/src/System/Object.cs index 0c8442b..ab4e43e 100644 --- a/src/System.Private.CoreLib/src/System/Object.cs +++ b/src/System.Private.CoreLib/src/System/Object.cs @@ -23,82 +23,15 @@ namespace System // services to subclasses. These services include object synchronization and support for clone // operations. // - [Serializable] [ClassInterface(ClassInterfaceType.AutoDispatch)] [ComVisible(true)] - [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] - public class Object + public partial class Object { - // Creates a new instance of an Object. - [NonVersionable] - public Object() - { - } - - // Returns a String which represents the object instance. The default - // for an object is to return the fully qualified name of the class. - // - public virtual string ToString() - { - return GetType().ToString(); - } - - // Returns a boolean indicating if the passed in object obj is - // Equal to this. Equality is defined as object equality for reference - // types and bitwise equality for value types using a loader trick to - // replace Equals with EqualsValue for value types). - // - - public virtual bool Equals(object obj) - { - return RuntimeHelpers.Equals(this, obj); - } - - public static bool Equals(object objA, object objB) - { - if (objA == objB) - { - return true; - } - if (objA == null || objB == null) - { - return false; - } - return objA.Equals(objB); - } - - [NonVersionable] - public static bool ReferenceEquals(object objA, object objB) - { - return objA == objB; - } - - // GetHashCode is intended to serve as a hash function for this object. - // Based on the contents of the object, the hash function will return a suitable - // value with a relatively random distribution over the various inputs. - // - // The default implementation returns the sync block index for this instance. - // Calling it on the same object multiple times will return the same value, so - // it will technically meet the needs of a hash function, but it's less than ideal. - // Objects (& especially value classes) should override this method. - // - public virtual int GetHashCode() - { - return RuntimeHelpers.GetHashCode(this); - } - // Returns a Type object which represent this object instance. // [MethodImplAttribute(MethodImplOptions.InternalCall)] public extern Type GetType(); - // Allow an object to free resources before the object is reclaimed by the GC. - // - [NonVersionable] - ~Object() - { - } - // Returns a new object instance that is a memberwise copy of this // object. This is always a shallow copy of the instance. The method is protected // so that other object may only call this method on themselves. It is entended to -- 2.7.4