MarshalByRefObject.MemberwiseClone(Boolean) MarshalByRefObject.MemberwiseClone(Boolean) MarshalByRefObject.MemberwiseClone(Boolean) MarshalByRefObject.MemberwiseClone(Boolean) Method

定義

建立目前物件的淺層複本。Creates a shallow copy of the current object.

建立目前 MarshalByRefObject 物件的淺層複本。Creates a shallow copy of the current MarshalByRefObject object.

protected:
 MarshalByRefObject ^ MemberwiseClone(bool cloneIdentity);
protected MarshalByRefObject MemberwiseClone (bool cloneIdentity);
override this.MemberwiseClone : bool -> MarshalByRefObject
Protected Function MemberwiseClone (cloneIdentity As Boolean) As MarshalByRefObject

參數

cloneIdentity
Boolean Boolean Boolean Boolean

false,刪除目前 MarshalByRefObject 物件的識別 (Identity),則會在跨遠端界限進行封送處理時將新的識別指定給物件。false to delete the current MarshalByRefObject object's identity, which will cause the object to be assigned a new identity when it is marshaled across a remoting boundary. false 的值通常是適當的。A value of false is usually appropriate. true 表示會將目前 MarshalByRefObject 物件的識別複製到其複製品,而造成將遠端用戶端呼叫傳送至遠端伺服器物件。true to copy the current MarshalByRefObject object's identity to its clone, which will cause remoting client calls to be routed to the remote server object.

傳回

目前 MarshalByRefObject 物件的淺層複本。A shallow copy of the current MarshalByRefObject object.

備註

MemberwiseClone(Boolean)方法來建立新建立的淺層複製MarshalByRefObject物件,然後再複製目前的非靜態欄位MarshalByRefObject物件與新的物件。The MemberwiseClone(Boolean) method creates a shallow copy by creating a new MarshalByRefObject object, and then copying the nonstatic fields of the current MarshalByRefObject object to the new object. 如果欄位是實值型別,則會執行位元欄位的複本。If a field is a value type, a bit-by-bit copy of the field is performed. 如果欄位是參考型別,則會複製參考,但參考的物件不;因此,原始的物件和其複製品參考相同的物件。If a field is a reference type, the reference is copied but the referred object is not; therefore, the original object and its clone refer to the same object.

例如,假設MarshalByRefObject呼叫參考物件 A 和 B 的 X 物件,則是參照物件 c。X 的淺層複本建立新物件,X2,也會參考物件 A 和 b。相反地,X 的深層複本建立新物件 X2 A2 和 B2,也就是 A 的複本的新物件和 B.B2,則是參照複本 C.使用可實作類別的新物件 C2、ICloneable介面,以執行深層或淺層 c複製的物件。For example, consider a MarshalByRefObject object called X that references objects A and B. Object B, in turn, references object C. A shallow copy of X creates new object X2 that also references objects A and B. In contrast, a deep copy of X creates a new object X2 that references the new objects A2 and B2, which are copies of A and B. B2, in turn, references the new object C2, which is a copy C. Use a class that implements the ICloneable interface to perform a deep or shallow copy of an object.

識別MarshalByRefObject物件會定義為目標的遠端用戶端呼叫遠端伺服器物件。The identity of a MarshalByRefObject object is defined as the remote server object that is the target of a remoting client call. 根據預設,成員複製品MarshalByRefObject物件具有相同的身分識別與原始物件,而且通常不會跨遠端界限與用戶端會封送處理的伺服器端物件的複製正確的行為。By default, the memberwise clone of a MarshalByRefObject object has the same identity as the original object, which is typically not the correct behavior for clones of server-side objects that are marshaled across a remoting boundary to the client side. 指定false,這通常是適當,刪除複製的身分識別,並導致複製會跨遠端界限,封送處理時,指派新的身分識別或true導致保留的原始身分識別複製MarshalByRefObject物件。Specify false, which is usually appropriate, to delete the identity of the clone and cause a new identity to be assigned when the clone is marshaled across a remoting boundary, or true to cause the clone to retain the identity of the original MarshalByRefObject object. MemberwiseClone(Boolean)方法要供開發人員實作遠端伺服器物件。The MemberwiseClone(Boolean) method is intended to be used by developers implementing remote server objects.

適用於