Exemplo n.º 1
0
        // 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 intended to
        // support the ICloneable interface.
        //
        //| <include path='docs/doc[@for="Object.MemberwiseClone"]/*' />
        // BUGBUG: maybe we can try harder to mess up the GC?
        protected Object MemberwiseClone()
        {
            if (this is String)
            {
                return(this);
                // REVIEW: ok, but what in the world is the CLR doing?
            }
            Thread thread = Thread.CurrentThread;

            if (this is Array)
            {
                Array srcArray = (Array)this;
                Array cloneArray;
                int   srcLength = srcArray.Length;
                if (srcArray.IsVector)
                {
                    cloneArray = GC.AllocateVector(srcArray.vtable, srcLength);
                    CloneVectorContents(srcArray, cloneArray);
                }
                else
                {
                    int rank = srcArray.Rank;
                    cloneArray =
                        GC.AllocateArray(srcArray.vtable, rank, srcLength);
                    CloneArrayContents(srcArray, cloneArray);
                }
                return(cloneArray);
            }
            else
            {
                Object clone = GC.AllocateObject(this.vtable);
                CloneObjectContents(this, clone);
                return(clone);
            }
        }