{"id":19991606,"url":"https://github.com/kfinley/TypeMerger","last_synced_at":"2025-05-04T10:32:04.358Z","repository":{"id":45302926,"uuid":"48620556","full_name":"kfinley/TypeMerger","owner":"kfinley","description":"A simple convention-based object merger for .NET Core.","archived":false,"fork":false,"pushed_at":"2023-06-26T19:35:00.000Z","size":65,"stargazers_count":83,"open_issues_count":0,"forks_count":26,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-05-01T12:48:20.122Z","etag":null,"topics":["csharp"],"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/kfinley.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2015-12-26T18:54:12.000Z","updated_at":"2024-11-22T02:26:20.000Z","dependencies_parsed_at":"2024-11-13T04:54:01.233Z","dependency_job_id":"af7996aa-3fd0-4b54-897b-0212f9d7ee8d","html_url":"https://github.com/kfinley/TypeMerger","commit_stats":{"total_commits":32,"total_committers":4,"mean_commits":8.0,"dds":0.34375,"last_synced_commit":"2e529cdd4dde10b2acbc62f91761d237fd850660"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kfinley%2FTypeMerger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kfinley%2FTypeMerger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kfinley%2FTypeMerger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kfinley%2FTypeMerger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kfinley","download_url":"https://codeload.github.com/kfinley/TypeMerger/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252320492,"owners_count":21729138,"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"],"created_at":"2024-11-13T04:51:50.086Z","updated_at":"2025-05-04T10:32:04.353Z","avatar_url":"https://github.com/kfinley.png","language":"C#","funding_links":[],"categories":["C\\#"],"sub_categories":[],"readme":"# TypeMerger - Merge two objects into one\n\nTypeMerger is a simple convention-based object merger for .NET Core. It allows two objects of any type to be merged into a new ``Type``. Object properties can be ignored and any collisions can be resolved using a fluent api. The object returned is a new ``Type`` that is dynamically generated and loaded using ``System.Reflection.Emit``.\n\n## Dependencies\nNone\n## How is it used?\n\n### Simple usage\nThis will result in a new object that has All the properties from obj1 and obj2.\n```\nvar result = TypeMerger.Merge(obj1, obj2);\n```\n\n### Ignore Certain Properties\nThis will result in a new object that has all of the properties from Obj1 and Obj2 Except for ``SomeProperty`` from obj1 and ``AnotherProperty`` from obj2.\n```\nvar result = TypeMerger.Ignore(() =\u003e obj1.SomeProperty)\n                       .Ignore(() =\u003e obj2.AnotherProperty)\n                       .Merge(obj1, obj2); \n\n```\n\n### What About Collisions? \nIf both objects have the same property there is a fluent method that will tell the ``Merger`` which object to use for that property. You simply tell the ``Merger`` which property to ``Use``.\n\nIn this example given obj1 and obj2 that both have ``SomeProperty``, the value from obj2 will be used.\n```\nvar result = TypeMerger.Use(() =\u003e obj2.SomeProperty)\n                       .Merge(obj1, obj2);\n```\n\n#### *What about collisions which ``Use`` hasn't specified which object's property to use?*\n\nIf both objects have the same property, and you do not specify which one to ``Use``, then the property from the **first** object passed to ``Merge`` will be used. (Look at the ``Merge_Types_with_Name_Collision`` unit test for an example.)\n\n### Mix \u0026 Match Your Merge\nCombining the ``.Ignore`` and ``.Use`` fluent methods allows you to pick and choose what you want from your objects.\n\n```\nvar obj1 = new {\n    SomeProperty = \"foo\",\n    SomeAmount = 20,\n    AnotherProperty = \"yo\"\n};\n\nvar obj2 = new {\n    SomeProperty = \"bar\",\n    SomePrivateStuff = \"SECRET!!\",\n    SomeOtherProperty = \"more stuff\"\n};\n\nvar result = TypeMerger.Ignore(() =\u003e obj1.AnotherProperty)\n                       .Use(() =\u003e obj2.SomeProperty)\n                       .Ignore(() =\u003e obj2.SomePrivateStuff)\n                       .Merge(obj1, obj2);\n```\n\nThe result object will have the following properties and values:\n\n    SomeProperty: \"bar\"\n    SomeAmount: 20\n    SomeOtherProperty: \"more stuff\"\n\n\n\n\n## History\nThe code is based on the original TypeMerger class written by [Mark Miller](http://www.developmentalmadness.com/). Updated, enhanced, and now maintained by [Kyle Finley](https://twitter.com/kfinley).\n\nOriginal posting: [KyleFinley.net/typemerger](http://goo.gl/qJ9FqN)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkfinley%2FTypeMerger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkfinley%2FTypeMerger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkfinley%2FTypeMerger/lists"}