Export (0) Print
Expand All

MarshalByRefObject.MemberwiseClone Method (Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

protected MarshalByRefObject MemberwiseClone(
	bool cloneIdentity
)

Parameters

cloneIdentity
Type: System.Boolean

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. A value of false is usually appropriate. 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.

Return Value

Type: System.MarshalByRefObject
A shallow copy of the current MarshalByRefObject object.

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.

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.

The identity of a MarshalByRefObject object is defined as the remote server object that is the target of a remoting client call. 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. 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. The MemberwiseClone(Boolean) method is intended to be used by developers implementing remote server objects.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft