CSharpEssentials.Clone
8.0.0
dotnet add package CSharpEssentials.Clone --version 8.0.0
NuGet\Install-Package CSharpEssentials.Clone -Version 8.0.0
<PackageReference Include="CSharpEssentials.Clone" Version="8.0.0" />
<PackageVersion Include="CSharpEssentials.Clone" Version="8.0.0" />
<PackageReference Include="CSharpEssentials.Clone" />
paket add CSharpEssentials.Clone --version 8.0.0
#r "nuget: CSharpEssentials.Clone, 8.0.0"
#:package CSharpEssentials.Clone@8.0.0
#addin nuget:?package=CSharpEssentials.Clone&version=8.0.0
#tool nuget:?package=CSharpEssentials.Clone&version=8.0.0
CSharpEssentials.Clone
ICloneable<out T>, a typed alternative to System.ICloneable with a single T Clone() method, plus extensions that clone every item of an IEnumerable<T> or IQueryable<T>. The library only calls Clone(); your implementation decides how deep the copy goes.
Benchmarks of Clone().ToList(), the array and lazy sources and the IQueryable<T> overload against hand-written loops, List<T>.ConvertAll and Array.ConvertAll at 10 and 1,000 items are in BENCHMARKS.md.
Installation
dotnet add package CSharpEssentials.Clone
Targets net11.0, net10.0, net9.0, netstandard2.1 and netstandard2.0.
Usage
Implementing ICloneable<T>
using CSharpEssentials.Clone;
public class User : ICloneable<User>
{
public string Name { get; set; } = string.Empty;
public Address Address { get; set; } = new();
public User Clone() => new()
{
Name = Name,
Address = Address.Clone()
};
}
public class Address : ICloneable<Address>
{
public string City { get; set; } = string.Empty;
public Address Clone() => new() { City = City };
}
User original = new() { Name = "Alice", Address = new Address { City = "NYC" } };
User clone = original.Clone();
clone.Address.City = "LA"; // original.Address.City is still "NYC"
A single object has no extension method: Clone() is the instance method you implement.
Cloning collections
List<User> users = [new() { Name = "Alice" }, new() { Name = "Bob" }];
List<User> cloned = users.Clone().ToList();
IQueryable<User> query = users.AsQueryable();
IQueryable<User> clonedQuery = query.Clone();
Both extensions require T : ICloneable<T> and are lazy: Clone() runs for each element as the result is enumerated, so call ToList() to materialize the copies once. There is no array overload; Clone() on a variable typed T[] binds to Array.Clone(), a shallow copy that returns object. Use ((IEnumerable<T>)array).Clone().ToArray() to clone the items.
The IQueryable<T> overload returns an in-memory query (EnumerableQuery<T>). It does not translate the cloning into the provider's query: a provider-backed query is read as usual and then cloned in memory. Because EnumerableQuery<T> compiles expression trees at run time, the overload is marked [RequiresUnreferencedCode] and [RequiresDynamicCode]; use the IEnumerable<T> overload in trimmed or Native AOT apps.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. net11.0 is compatible. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
-
.NETStandard 2.1
- No dependencies.
-
net10.0
- No dependencies.
-
net11.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on CSharpEssentials.Clone:
| Package | Downloads |
|---|---|
|
CSharpEssentials
A comprehensive C# library enhancing functional programming capabilities with type-safe monads (Maybe, Result), discriminated unions (Any), and robust error handling. Features include: domain-driven design support, enhanced Entity Framework integration, testable time management, JSON utilities, and LINQ extensions. Built for modern C# development with focus on maintainability, testability, and functional programming principles. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 8.0.0 | 156 | 11/9/2026 |
| 7.0.0 | 153 | 10/20/2026 |
| 6.5.2 | 134 | 10/10/2026 |
| 6.5.1 | 121 | 10/10/2026 |
| 6.5.0 | 138 | 10/9/2026 |
| 6.4.0 | 136 | 10/9/2026 |
| 6.3.0 | 133 | 10/8/2026 |
| 6.2.0 | 131 | 10/8/2026 |
| 6.1.0 | 133 | 10/7/2026 |
| 6.0.0 | 130 | 10/7/2026 |
| 5.2.1 | 139 | 10/7/2026 |
| 5.2.0 | 140 | 10/7/2026 |
| 5.1.0 | 133 | 10/7/2026 |
| 5.0.0 | 136 | 10/6/2026 |
| 4.1.0 | 138 | 10/6/2026 |
| 4.0.0 | 140 | 10/5/2026 |
| 3.2.3 | 344 | 5/31/2026 |
| 3.2.2 | 174 | 5/31/2026 |
| 3.2.1 | 182 | 5/31/2026 |
| 3.2.0 | 173 | 5/30/2026 |