ObjectExtensionsDeepCloneT(T, FuncObject, Object) Method

Clones an object by deep cloning.

Definition

Namespace: KGySoft.CoreLibraries
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 8.0.0
C#
public static T DeepClone<T>(
	this T obj,
	Func<Object, Object?>? customClone
)

Parameters

obj  T
The object to clone.
customClone  FuncObject, Object
An optional delegate that can be used to customize the cloning of individual instances. If specified, then it is always called with a non- instance. If it returns , then the input object will be cloned by using the default logic.

Type Parameters

T
Type of the object

Return Value

T
The clone of the object.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type T. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

If customClone is , then this method returns a functionally equivalent clone of the original object.

String, Delegate and runtime Type instances are not cloned but their original reference is returned in the result. This can be overridden by handling these types in customClone.

See Also