Note
Obsolete Note: This overload uses the BinarySerializationFormatter internally, which is not always applicable.
It is recommended to use the DeepCloneT(T, FuncObject, Object) overload instead.
[ObsoleteAttribute("This DeepClone overload is obsolete. Use the DeepClone<T>(T,Func<object,object?>?) overload instead.")]
public static T DeepClone<T>(
this T obj,
bool ignoreCustomSerialization = false
)
<ExtensionAttribute>
<ObsoleteAttribute("This DeepClone overload is obsolete. Use the DeepClone<T>(T,Func<object,object?>?) overload instead.")>
Public Shared Function DeepClone(Of T) (
obj As T,
Optional ignoreCustomSerialization As Boolean = false
) As T
public:
[ExtensionAttribute]
[ObsoleteAttribute(L"This DeepClone overload is obsolete. Use the DeepClone<T>(T,Func<object,object?>?) overload instead.")]
generic<typename T>
static T DeepClone(
T obj,
bool ignoreCustomSerialization = false
)
[<ExtensionAttribute>]
[<ObsoleteAttribute("This DeepClone overload is obsolete. Use the DeepClone<T>(T,Func<object,object?>?) overload instead.")>]
static member DeepClone :
obj : 'T *
?ignoreCustomSerialization : bool
(* Defaults:
let _ignoreCustomSerialization = defaultArg ignoreCustomSerialization false
*)
-> 'T
This method makes possible to clone objects even if their type is not marked by the SerializableAttribute; however, in such case it is not guaranteed that the result is functionally equivalent to the input object.
If ignoreCustomSerialization is , then it is not guaranteed that the object can be cloned in all circumstances (see the note above).
On the other hand, if ignoreCustomSerialization is , then it can happen that even singleton types will be deep cloned. The cloning is performed by the BinarySerializationFormatter class, which supports some singleton types natively (such as Type and DBNull), which will be always cloned correctly.
In .NET Framework remote objects are cloned in a special way and the result is always a local object. The ignoreCustomSerialization parameter is ignored for remote objects.