{"id":15035804,"url":"https://github.com/replaysmike/anyclone","last_synced_at":"2025-04-09T23:20:43.729Z","repository":{"id":48401517,"uuid":"157807360","full_name":"replaysMike/AnyClone","owner":"replaysMike","description":"A CSharp library that can deep clone any object using only reflection.","archived":false,"fork":false,"pushed_at":"2022-12-08T14:49:56.000Z","size":234,"stargazers_count":50,"open_issues_count":8,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-09T04:29:35.126Z","etag":null,"topics":["csharp","csharp-code","deep-clone","netstandard","reflection"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/replaysMike.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-16T03:26:05.000Z","updated_at":"2025-04-07T03:36:28.000Z","dependencies_parsed_at":"2023-01-25T14:01:15.923Z","dependency_job_id":null,"html_url":"https://github.com/replaysMike/AnyClone","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/replaysMike%2FAnyClone","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/replaysMike%2FAnyClone/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/replaysMike%2FAnyClone/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/replaysMike%2FAnyClone/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/replaysMike","download_url":"https://codeload.github.com/replaysMike/AnyClone/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248126238,"owners_count":21051885,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","csharp-code","deep-clone","netstandard","reflection"],"created_at":"2024-09-24T20:29:31.350Z","updated_at":"2025-04-09T23:20:43.708Z","avatar_url":"https://github.com/replaysMike.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AnyClone\n[![nuget](https://img.shields.io/nuget/v/AnyClone.svg)](https://www.nuget.org/packages/AnyClone/)\n[![nuget](https://img.shields.io/nuget/dt/AnyClone.svg)](https://www.nuget.org/packages/AnyClone/)\n[![Build status](https://ci.appveyor.com/api/projects/status/xr7gebcdins0hs4f?svg=true)](https://ci.appveyor.com/project/MichaelBrown/anyclone)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/24f78d682c844168809617fd56ecad0f)](https://www.codacy.com/app/replaysMike/AnyClone?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=replaysMike/AnyClone\u0026amp;utm_campaign=Badge_Grade)\n[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/24f78d682c844168809617fd56ecad0f)](https://www.codacy.com/app/replaysMike/AnyClone?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=replaysMike/AnyClone\u0026utm_campaign=Badge_Coverage)\n\nA CSharp library that can deep clone any object using only reflection.\n\nNo requirements for `[Serializable]` attributes, supports standard ignore attributes.\n\n## Description\n\nI 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.\n\n## Installation\nInstall AnyClone from the Package Manager Console:\n```\nPM\u003e Install-Package AnyClone\n```\n\n## Usage\n\n```csharp\nusing AnyClone.Extensions;\n\nvar originalObject = new SomeComplexTypeWithDeepStructure();\nvar myClonedObject = originalObject.Clone();\n```\n\nCapture Errors\n```csharp\nusing AnyClone.Extensions;\n\nvar originalObject = new SomeComplexTypeWithDeepStructure();\n// capture errors found with your object where impossible situations occur, and add [IgnoreDataMember] to those properties/fields.\n\nvar myClonedObject = originalObject.Clone((ex, path, property, obj) =\u003e {\n  Console.WriteLine($\"Cloning error: {path} {ex.Message}\");\n  Assert.Fail();\n});\n```\n\nGet differences between cloned objects using [AnyDiff](https://github.com/replaysMike/AnyDiff)\n```csharp\nusing AnyClone.Extensions;\nusing AnyDiff;\n\nvar object1 = new MyComplexObject(1, \"A string\");\nvar object1Snapshot = object1.Clone();\n\nvar diff = AnyDiff.Diff(object1, object1Snapshot);\nAssert.AreEqual(diff.Count, 0);\n\n// change something anywhere in the object tree\nobject1.Name = \"A different string\";\n\ndiff = AnyDiff.Diff(object1, object1Snapshot);\nAssert.AreEqual(diff.Count, 1);\n```\n\n### Ignoring Properties/Fields\nThere are unfortunately a few situations that can't be resolved, such as cloning delegates, events etc. Fortunately, you can specify attributes that AnyClone will skip properties decorated with them. By default, AnyClone will ignore properties decorated with the following attributes: `IgnoreDataMemberAttribute, NonSerializedAttribute, JsonIgnoreAttribute`. If you wish to disable this behavior, or provide other attributes that you wish to decorate properties to ignore you can provide a custom CloneConfiguration:\n\n```csharp\nusing AnyClone;\nusing AnyClone.Extensions;\n\nvar originalObject = new SomeComplexTypeWithDeepStructure();\nvar myClonedObject = originalObject.Clone(CloneConfiguration.UsingAttributeNamesToIgnore(\"IgnoreDataMemberAttribute\", \"MyCustomAttribute\"));\n```\n\nBoth attribute names and attribute types can be specified:\n```csharp\nvar myClonedObject = originalObject.Clone(CloneConfiguration.UsingAttributeNamesToIgnore(\"IgnoreDataMemberAttribute\", \"MyCustomAttribute\"));\nvar myOtherClonedObject = originalObject.Clone(CloneConfiguration.UsingAttributesToIgnore(typeof(IgnoreDataMemberAttribute), typeof(MyCustomAttribute)));\n```\n\n### Other Applications\n\nIf you need to perform serialization instead of deep copying, try out [AnySerializer](https://github.com/replaysMike/AnySerializer) which doesn't require attribute decoration and works on complex structures.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freplaysmike%2Fanyclone","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freplaysmike%2Fanyclone","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freplaysmike%2Fanyclone/lists"}