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

如果要删除当前 MarshalByRefObject 对象的标识,则为 false,这使该对象在跨远程边界封送时分配一个新标识。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对象名为 X 的引用对象 A 和 B,反过来,引用对象 c。X 的浅表副本创建新对象 X2,它还引用对象 A 和 b。与此相反,X 的深层副本创建引用 A2 和 B2,是的一个副本的新对象的新对象 X2 和 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.

适用于