{"id":28317750,"url":"https://github.com/igece/objdiff","last_synced_at":"2025-06-24T15:32:07.125Z","repository":{"id":46237289,"uuid":"370798937","full_name":"igece/ObjDiff","owner":"igece","description":"A C# .NET Standard library that allows to check for equality and obtain the differences between two objects using reflection. The comparison process can be configured in many ways.","archived":false,"fork":false,"pushed_at":"2023-01-22T21:50:28.000Z","size":67,"stargazers_count":9,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-01T14:18:42.320Z","etag":null,"topics":["compare-objects","csharp","diff","differences","dotnet-framework","dotnet-standard","equality","patch"],"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/igece.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":"2021-05-25T18:58:28.000Z","updated_at":"2025-03-25T10:27:13.000Z","dependencies_parsed_at":"2023-02-12T18:31:06.207Z","dependency_job_id":null,"html_url":"https://github.com/igece/ObjDiff","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/igece/ObjDiff","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igece%2FObjDiff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igece%2FObjDiff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igece%2FObjDiff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igece%2FObjDiff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/igece","download_url":"https://codeload.github.com/igece/ObjDiff/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igece%2FObjDiff/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261703104,"owners_count":23196898,"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":["compare-objects","csharp","diff","differences","dotnet-framework","dotnet-standard","equality","patch"],"created_at":"2025-05-25T06:12:38.074Z","updated_at":"2025-06-24T15:32:07.109Z","avatar_url":"https://github.com/igece.png","language":"C#","readme":"# ObjDiff\n\n[![nuget](https://img.shields.io/nuget/v/ObjDiff.svg)](https://www.nuget.org/packages/ObjDiff)\n[![nuget](https://img.shields.io/nuget/dt/ObjDiff.svg)](https://www.nuget.org/packages/ObjDiff)\n[![Build](https://github.com/igece/ObjDiff/actions/workflows/CI_build.yml/badge.svg)](https://github.com/igece/ObjDiff/actions/workflows/CI_build.yml)\n[![Unit Tests](https://github.com/igece/ObjDiff/actions/workflows/CI_Tests.yml/badge.svg)](https://github.com/igece/ObjDiff/actions/workflows/CI_Tests.yml)\n\nA C# .NET Standard library that allows to check for equality and obtain the differences between two objects using reflection.\nThe comparison process can be configured in many ways so, e.g., it can ignore certain properties.\n\nOptionally, these differences can be used to patch the first object so it becomes equal to the second one.\nThis patching feature is specially useful when updating Entity Framework entities as it allows to atomically\nupdate only those properties that have really changed.\n\n\n\n## Installation\n\nUsing .NET CLI:\n\n```\ndotnet add package ObjDiff\n```\n\nUsing NuGet package manager console:\n\n```\nInstall-Package ObjDiff\n```\n\n\n\n## Features\n\n* Compares arrays and collections.\n* Compares children objects.\n* Configuration options to ignore specific elements.\n* Patch an object with an obtained set of differences.\n\n## Limitations\n\n* Only allows to compare objects of the same type.\n* Only public properties are compared.\n\n## Usage\n\n### Obtaining Differences\n\n``` csharp\nusing ObjDiff;\n\nvar object1 = new CustomObject();\nvar object2 = new CustomObject();\n\nIEnumerable\u003cDifference\u003e differences = ObjDiff.Diff(object1, object2);\n```\n\nThe last line can also be expressed through the use of the `Diff` extension method:\n\n``` csharp\nIEnumerable\u003cDifference\u003e differences = object1.Diff(object2);\n```\n\nThe `Diff` method returns a list with all the differences found between `object1` and `object2` instances. Each one of these differences are represented through an instance of the `Difference` class:\n\n``` csharp\n  public class Difference\n  {\n      /// Full path of the element were values differ between compared objects.\n      public string Path { get; private set; }\n\n      /// Value of the object being compared.\n      public object LeftValue { get; private set; }\n\n      /// Value of the object against LeftValue is being compared.\n      public object RightValue { get; private set; }\n  }\n```\n\n### Comparison Options\n\nIt is possible to customize how the comparison process will perform:\n\n``` csharp\nvar differences = object1.Diff(object2, new CompareOptions { MaxDepth = 10 });\n```\n\nThe available options are:\n\n``` csharp\npublic class CompareOptions\n{\n    /// When comparing arrays/collections, items must be in the same order. Default value is true.\n    public bool CollectionsSameOrder { get; set; }\n\n    /// Ignore properties marked with any of the specified attribute names. None set by default.\n    public string[] IgnoredAttributes { get; set; }\n\n    /// Ignore properties named with any of the specified values. None set by default.\n    public string[] IgnoredProperties { get; set; }\n\n    /// Don't dive into any property named with any of the specified values. None set by default.\n    public string[] DontDiveProperties { get; set; }\n\n    /// Maximum number of children levels to dive into. Default value is 10.\n    public uint MaxDepth { get; set; }    \n}\n```\n\n### Ignoring Properties\n\nAny property marked with the `IgnoreDifferences` attribute will always be skipped during the comparison process, no matter\nthe actual value of the `IgnoredAttributes` property if `CompareOptions` is used.\n\n``` csharp\npublic class SampleClass\n{\n    [IgnoreDifferences]\n    public string SampleProperty { get; set; }\n}\n```\n\n### Patching\n\nOnce we have the differences between two objects, we can apply them (patch) to the original object being compared. After patching it, both objects should be equivalent.\n\n``` csharp\nobject1.Patch(differences);\nAssert.Equal(object1, object2);\n```\n\nBoth `Diff` and `Patch` operations can be executed through a simple call:\n\n``` csharp\nObjDiff.MakeEqual(object1, object2, compareOptions);\n```\n\nOr using `MakeEqualTo` extension method:\n\n``` csharp\nobject1.MakeEqualTo(object2, compareOptions);\n```\n\n### Checking Equality\n\nThe library also offers a method to easily check that two objects are equal (attending to ObjDiff rules):\n\n``` csharp\nObjDiff.AreEqual(object1, object2, compareOptions);\n```\n\nOr using `IsEqualTo` extension method:\n\n``` csharp\nobject1.IsEqualTo(object2, compareOptions);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figece%2Fobjdiff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Figece%2Fobjdiff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figece%2Fobjdiff/lists"}