AnyClone 1.0.55
See the version list below for details.
dotnet add package AnyClone --version 1.0.55
NuGet\Install-Package AnyClone -Version 1.0.55
<PackageReference Include="AnyClone" Version="1.0.55" />
paket add AnyClone --version 1.0.55
#r "nuget: AnyClone, 1.0.55"
// Install AnyClone as a Cake Addin #addin nuget:?package=AnyClone&version=1.0.55 // Install AnyClone as a Cake Tool #tool nuget:?package=AnyClone&version=1.0.55
AnyClone
A CSharp library that can deep clone any object using only reflection.
No requirements for [Serializable]
attributes, supports standard ignore attributes.
Description
I built this library as almost all others I tried on complex objects either didn't work at all, or failed to account for common scenarios. Serialization required too much boiler plate (BinarySerialization, Protobuf, or Json.Net) and fails to account for various designs. Implementing IClonable was too much of a chore and should be unnecessary. Various projects that use expression trees also failed to work, IObservable patterns were difficult to implement on large, already written code base.
Installation
Install AnyClone from the Package Manager Console:
PM> Install-Package AnyClone
Usage
using AnyClone;
var originalObject = new SomeComplexTypeWithDeepStructure();
var myClonedObject = originalObject.Clone();
Capture Errors
using AnyClone;
var originalObject = new SomeComplexTypeWithDeepStructure();
// capture errors found with your object where impossible situations occur, and add [IgnoreDataMember] to those properties/fields.
var myClonedObject = originalObject.Clone((ex, path, property, obj) => {
Console.WriteLine($"Cloning error: {path} {ex.Message}");
Assert.Fail();
});
Get differences between cloned objects using AnyDiff
using AnyDiff;
var object1 = new MyComplexObject(1, "A string");
var object1Snapshot = object1.Clone();
var diff = AnyDiff.Diff(object1, object1Snapshot);
Assert.AreEqual(diff.Count, 0);
// change something anywhere in the object tree
object1.Name = "A different string";
diff = AnyDiff.Diff(object1, object1Snapshot);
Assert.AreEqual(diff.Count, 1);
Ignoring Properties/Fields
There are unfortunately a few situations that can't be resolved, such as cloning delegates, events etc. Fortunately, and for most scenarios you don't want these anyways so you can use any of the standard supported attributes to ignore these properties: [IgnoreDataMember]
, [JsonIgnore]
, and [NonSerialized]
(fields only, just use [IgnoreDataMember]
and save yourself the hassle).
Other Applications
If you need to perform serialization instead of deep copying, try out AnySerializer which doesn't require attribute decoration and works on complex structures.
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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
.NET Framework | net40 is compatible. net403 was computed. net45 is compatible. net451 was computed. net452 was computed. net46 is compatible. net461 is compatible. net462 is compatible. net463 was computed. net47 is compatible. net471 was computed. net472 was computed. net48 is compatible. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.0
- ILRepack.Lib.MSBuild.Task (>= 2.0.18.2)
-
.NETFramework 4.5
- ILRepack.Lib.MSBuild.Task (>= 2.0.18.2)
-
.NETFramework 4.6
- ILRepack.Lib.MSBuild.Task (>= 2.0.18.2)
-
.NETFramework 4.6.1
- ILRepack.Lib.MSBuild.Task (>= 2.0.18.2)
-
.NETFramework 4.6.2
- ILRepack.Lib.MSBuild.Task (>= 2.0.18.2)
-
.NETFramework 4.7
- ILRepack.Lib.MSBuild.Task (>= 2.0.18.2)
-
.NETFramework 4.8
- ILRepack.Lib.MSBuild.Task (>= 2.0.18.2)
-
.NETStandard 2.1
- ILRepack.Lib.MSBuild.Task (>= 2.0.18.2)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on AnyClone:
Package | Downloads |
---|---|
Blazor-State
A Blazor state management library by TimeWarp |
|
IdOps.Server
Package Description |
|
TimeWarp.State
A Blazor state management library by TimeWarp |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on AnyClone:
Repository | Stars |
---|---|
TimeWarpEngineering/timewarp-state
A Blazor State management library by TimeWarp.
|
Version | Downloads | Last updated |
---|---|---|
1.1.6 | 215,241 | 6/20/2022 |
1.1.3 | 444 | 6/20/2022 |
1.1.2 | 43,009 | 9/15/2021 |
1.1.1 | 405 | 9/15/2021 |
1.1.0 | 1,016 | 9/15/2021 |
1.0.68 | 2,135 | 8/18/2021 |
1.0.67 | 381 | 8/11/2021 |
1.0.65 | 367 | 8/10/2021 |
1.0.64 | 361 | 8/10/2021 |
1.0.63 | 2,400 | 7/29/2021 |
1.0.62 | 384 | 7/29/2021 |
1.0.61 | 428 | 7/29/2021 |
1.0.57 | 429 | 7/28/2021 |
1.0.56 | 410 | 7/28/2021 |
1.0.55 | 439 | 7/28/2021 |
1.0.39 | 98,441 | 7/10/2020 |
1.0.37 | 604 | 7/9/2020 |
1.0.36 | 38,981 | 4/22/2020 |
1.0.35 | 503 | 4/22/2020 |
1.0.34 | 19,430 | 5/16/2019 |
1.0.31 | 1,096 | 4/20/2019 |
1.0.30 | 933 | 4/20/2019 |
1.0.29 | 955 | 4/20/2019 |
1.0.27 | 952 | 4/14/2019 |
1.0.24 | 2,531 | 1/11/2019 |
1.0.23 | 43,448 | 1/7/2019 |
1.0.22 | 1,019 | 12/29/2018 |
1.0.17 | 1,026 | 12/28/2018 |
1.0.11 | 12,789 | 12/4/2018 |
1.0.10 | 1,042 | 12/4/2018 |
1.0.9 | 1,038 | 12/2/2018 |
1.0.8 | 1,036 | 12/2/2018 |
1.0.6 | 1,036 | 11/29/2018 |
1.0.5 | 1,027 | 11/29/2018 |
1.0.4 | 1,083 | 11/28/2018 |
1.0.0 | 1,177 | 11/16/2018 |
Deep clone or copy any complex object without the hassle of serialization, decoration or custom mappings.