AnyClone 1.0.0
See the version list below for details.
dotnet add package AnyClone --version 1.0.0
NuGet\Install-Package AnyClone -Version 1.0.0
<PackageReference Include="AnyClone" Version="1.0.0" />
paket add AnyClone --version 1.0.0
#r "nuget: AnyClone, 1.0.0"
// Install AnyClone as a Cake Addin #addin nuget:?package=AnyClone&version=1.0.0 // Install AnyClone as a Cake Tool #tool nuget:?package=AnyClone&version=1.0.0
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.
Usage
var originalObject = new SomeComplexTypeWithDeepStructure();
var myClonedObject = originalObject.Clone();
Capture Errors
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).
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 | 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 was computed. |
.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
- Newtonsoft.Json (>= 12.0.1-beta1)
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 | 221,453 | 6/20/2022 |
1.1.3 | 445 | 6/20/2022 |
1.1.2 | 43,456 | 9/15/2021 |
1.1.1 | 407 | 9/15/2021 |
1.1.0 | 1,018 | 9/15/2021 |
1.0.68 | 2,137 | 8/18/2021 |
1.0.67 | 383 | 8/11/2021 |
1.0.65 | 371 | 8/10/2021 |
1.0.64 | 362 | 8/10/2021 |
1.0.63 | 2,402 | 7/29/2021 |
1.0.62 | 387 | 7/29/2021 |
1.0.61 | 432 | 7/29/2021 |
1.0.57 | 430 | 7/28/2021 |
1.0.56 | 412 | 7/28/2021 |
1.0.55 | 441 | 7/28/2021 |
1.0.39 | 98,789 | 7/10/2020 |
1.0.37 | 605 | 7/9/2020 |
1.0.36 | 38,984 | 4/22/2020 |
1.0.35 | 506 | 4/22/2020 |
1.0.34 | 19,435 | 5/16/2019 |
1.0.31 | 1,098 | 4/20/2019 |
1.0.30 | 934 | 4/20/2019 |
1.0.29 | 956 | 4/20/2019 |
1.0.27 | 953 | 4/14/2019 |
1.0.24 | 2,532 | 1/11/2019 |
1.0.23 | 43,454 | 1/7/2019 |
1.0.22 | 1,020 | 12/29/2018 |
1.0.17 | 1,027 | 12/28/2018 |
1.0.11 | 12,792 | 12/4/2018 |
1.0.10 | 1,044 | 12/4/2018 |
1.0.9 | 1,039 | 12/2/2018 |
1.0.8 | 1,037 | 12/2/2018 |
1.0.6 | 1,037 | 11/29/2018 |
1.0.5 | 1,028 | 11/29/2018 |
1.0.4 | 1,084 | 11/28/2018 |
1.0.0 | 1,179 | 11/16/2018 |
Deep clone or copy any complex object without the hassle of serialization, decoration or custom mappings.