{"id":22065858,"url":"https://github.com/karenpayneoregon/comparing-objects-csharp","last_synced_at":"2025-07-22T21:34:00.747Z","repository":{"id":110840356,"uuid":"365051302","full_name":"karenpayneoregon/comparing-objects-csharp","owner":"karenpayneoregon","description":"Comparing objects","archived":false,"fork":false,"pushed_at":"2022-11-30T14:17:57.000Z","size":97,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-23T18:17:33.371Z","etag":null,"topics":["comparable","compare","csharp","csharp11","iequalitycomparer"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/karenpayneoregon.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-06T22:22:11.000Z","updated_at":"2023-05-14T11:28:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"a50f7d49-98bd-4244-95a0-11b4f64efa1b","html_url":"https://github.com/karenpayneoregon/comparing-objects-csharp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/karenpayneoregon/comparing-objects-csharp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karenpayneoregon%2Fcomparing-objects-csharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karenpayneoregon%2Fcomparing-objects-csharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karenpayneoregon%2Fcomparing-objects-csharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karenpayneoregon%2Fcomparing-objects-csharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/karenpayneoregon","download_url":"https://codeload.github.com/karenpayneoregon/comparing-objects-csharp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karenpayneoregon%2Fcomparing-objects-csharp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266578638,"owners_count":23951148,"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","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["comparable","compare","csharp","csharp11","iequalitycomparer"],"created_at":"2024-11-30T19:22:19.153Z","updated_at":"2025-07-22T21:34:00.722Z","avatar_url":"https://github.com/karenpayneoregon.png","language":"C#","readme":"# About\n\nProvides various examples for comparing objects. Most examples on the web usually deal with simple list of string or int while code samples here show how to work with `List\u003cT\u003e`. Keep in mind that the examples are a starting point to learn from as it is not possible to cover all situations.\n\n:heavy_check_mark:  Code will be added over time.\n\n![img](assets/unitTesting.png) ![img](assets/csharpSmall.png)\n\n\n:heavy_check_mark: 11/30/2022 Updated to .NET Core 7 from .NET Core 5 which is out of support.\n\n\n---\n\n:white_circle: json read using System.Text.Json;\n\n:white_circle: JsonLibrary provides json read operations\n\n:white_circle: ApplicationDataLibrary containers comparers\n\n\n\n## Sample\n\n```csharp\n[TestMethod]\n[TestTraits(Trait.Distinct)]\npublic void FirstNameLastName_Equality_Comparer()\n{\n    var people = ReadPeopleFromFile;\n    people.Add(people[0]);\n    Assert.AreEqual(people.Count, 51);\n    \n    var distinct = people.Distinct(new FirstNameLastNameEqualityComparer());\n    \n    Assert.IsTrue(distinct.Count() == 50);\n}\n```\n\u003c/br\u003e\n\n```csharp\npublic class FirstNameComparer : IEqualityComparer\u003cPerson\u003e\n{\n    public bool Equals(Person x, Person y)\n    {\n        if (ReferenceEquals(x, y)) return true;\n        if (ReferenceEquals(x, null)) return false;\n        if (ReferenceEquals(y, null)) return false;\n        if (x.GetType() != y.GetType()) return false;\n        return x.FirstName == y.FirstName;\n    }\n\n    public int GetHashCode(Person obj)\n    {\n        return (obj.FirstName != null ? obj.FirstName.GetHashCode() : 0);\n    }\n}\n```\n\n### Wrappers\n\n```csharp\npublic class Wrappers\n{\n    public static IEqualityComparer\u003cPerson\u003e FirstNamEqualityComparer =\u003e \n        Equality\u003cPerson\u003e.CreateComparer(p =\u003e p.FirstName);\n    \n    public static IEqualityComparer\u003cPerson\u003e LastNamEqualityComparer =\u003e \n        Equality\u003cPerson\u003e.CreateComparer(p =\u003e p.LastName);\n    \n    public static LambdaEqualityComparer\u003cPerson\u003e FirstNameLambda =\u003e \n        new((p1, p2) =\u003e \n        p1.FirstName == p2.FirstName, x =\u003e x.FirstName.GetHashCode());\n    \n    public static LambdaEqualityComparer\u003cPerson\u003e LastNameLambda =\u003e \n        new((p1, p2) =\u003e \n        p1.LastName == p2.LastName, x =\u003e x.LastName.GetHashCode());\n}\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarenpayneoregon%2Fcomparing-objects-csharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkarenpayneoregon%2Fcomparing-objects-csharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarenpayneoregon%2Fcomparing-objects-csharp/lists"}