{"id":28174568,"url":"https://github.com/sanelli/mappa","last_synced_at":"2025-05-15T22:18:20.152Z","repository":{"id":285147378,"uuid":"564513953","full_name":"sanelli/Mappa","owner":"sanelli","description":"Map your classes via source-generated code.","archived":false,"fork":false,"pushed_at":"2025-05-11T19:55:18.000Z","size":1303,"stargazers_count":1,"open_issues_count":40,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-15T22:16:47.594Z","etag":null,"topics":["csharp","mapper","source-generator"],"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/sanelli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-11-10T22:02:39.000Z","updated_at":"2025-05-11T19:47:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"0ba2fa83-9da4-400b-9da8-7413c8e69b07","html_url":"https://github.com/sanelli/Mappa","commit_stats":null,"previous_names":["sanelli/mappa"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanelli%2FMappa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanelli%2FMappa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanelli%2FMappa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanelli%2FMappa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sanelli","download_url":"https://codeload.github.com/sanelli/Mappa/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254430295,"owners_count":22069909,"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","mapper","source-generator"],"created_at":"2025-05-15T22:16:43.679Z","updated_at":"2025-05-15T22:18:20.147Z","avatar_url":"https://github.com/sanelli.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🗺️ Mappa\n\n![Build main](https://github.com/sanelli/Mappa/actions/workflows/merge-main.yml/badge.svg)\n![Line Coverage](https://img.shields.io/endpoint?url=https%3A%2F%2Fgist.githubusercontent.com%2Fsanelli%2F7f4a85bc809328b4821b03125f9190cb%2Fraw%2FMAPPA-BADGE-LINE-COVERAGE.json)\n![Branch Coverage](https://img.shields.io/endpoint?url=https%3A%2F%2Fgist.githubusercontent.com%2Fsanelli%2F7f4a85bc809328b4821b03125f9190cb%2Fraw%2FMAPPA-BADGE-BRANCH-COVERAGE.json)\n![Method Coverage](https://img.shields.io/endpoint?url=https%3A%2F%2Fgist.githubusercontent.com%2Fsanelli%2F7f4a85bc809328b4821b03125f9190cb%2Fraw%2FMAPPA-BADGE-METHOD-COVERAGE.json)\n\nMappa (italian for _map_) is a source generator for `C#` that can generate code to allow the mapping between types, similarly to what [AutoMapper](https://www.nuget.org/packages/AutoMapper) (and other similar tools) does.\nSee [Documentation](./Documentation/README.md) for more details.\n\nThe main different between Mappa and AutoMapper is that Mappa generates code at compile time while AutoMapper only at runtime;\nthis has multiple benefits:\n- the code generated is optimised by the compiler;\n- the code generated is pure C# code that does not require any introspections;\n- the code generated works when AOT is required;\n- the code can be easily shared across different mappers;\n- fine-grained mapping can be obtained via attributes on the mapper methods without having to touch the source or the target classes;\n- mapper methods can be inside any class (static class and extension methods are supported!).\n- you do not need to specify every type that requires a mapping: if a mapping is missing Mappa will generate it for you;\n\n\n## 🧑‍🔬 A simple example\nConsider the following code snipped:\n```csharp\nusing Mappa;\nusing System.Collections.Generic;\n\nnamespace Sample;\n  \npublic enum MyEnumeration\n{\n    One,\n    Two,\n    Three,\n}\n\npublic class Source\n{\n    public int PropertyA {get;set;}\n    public int[] PropertyB {get;set;}\n    public MyEnumeration PropertyC {get;set;}\n}\n\npublic class Target\n{\n    public long PropertyA {get;set;}\n    public List\u003cstring\u003e PropertyB {get;set;}\n    public string PropertyC {get;set;}\n}\n\n[Mappa]\npublic partial class Mapper\n{\n    public partial Target Map(Source input);\n}\n```\n\nwill create mapping code like the following:\n```csharp\nnamespace Sample;\n\npublic partial class Mapper\n{\n   [System.CodeDom.Compiler.GeneratedCodeAttribute(\"Mappa\", \"0.0.1.0\")]\n   public partial Sample.Target Map(Sample.Source input)\n   {\n       long __mappa_tmp_1 = input.PropertyA;\n       int[] __mappa_tmp_2 = input.PropertyB;\n       System.Collections.Generic.List\u003cstring\u003e __mappa_tmp_3 = new System.Collections.Generic.List\u003cstring\u003e(__mappa_tmp_2.Length);\n       for (int __mappa_tmp_3 = 0; __mappa_tmp_3 \u003c __mappa_tmp_2.Length; ++__mappa_tmp_3)\n       {\n           int __mappa_tmp_4 = __mappa_tmp_2[__mappa_tmp_3];\n           string __mappa_tmp_5 = __mappa_tmp_4.ToString();\n           __mappa_tmp_3.Add(__mappa_tmp_5)\n       }\n       Sample.MyEnumeration __mappa_tmp_6 = input.PropertyC;\n       string __mappa_tmp_7;\n       switch(__mappa_tmp_6)\n       {\n           case Sample.MyEnumeration.One:\n              __mappa_tmp_7 = \"One\";\n              break;\n           case Sample.MyEnumeration.Two:\n              __mappa_tmp_7 = \"Two\";\n              break;\n           case Sample.MyEnumeration.Three:\n              __mappa_tmp_7 = \"Three\";\n              break;\n           default:\n              throw new System.OutOfRangeException(nameof(__mappa_tmp_6));\n       }\n       Sample.Target __mappa_tmp_8 = new Sample.Target()\n       {\n           PropertyA = __mappa_tmp_1,\n           PropertyB = __mappa_tmp_3,\n           PropertyC = __mappa_tmp_7;\n       }\n       return __mappa_tmp_8;\n   }\n}\n```\n\n## 🧑🏻‍💻 How to use Mappa\nThe easiest way to is import the NuGet packages and apply the `[Mappa]` attribute on the partial classes that contains the partial methods that needs to be generated.\n\nPlease see the [tutorial](./Documentation/tutorial.md) in the [documentation](./Documentation/README.md) provided.\n\nYou can also find many examples in the [Mappa.Samples](Mappa.Samples) project.\n\n## 📦 NuGet packages\n- [Mappa](https://www.nuget.org/packages/Mappa/): source generator that allows to automatically generate mapping between classes and value types;\n- [Mappa source generator](https://www.nuget.org/packages/Mappa.Generator/): source generator that allows to automatically generate mapping between classes and value types;\n- [Mappa Protobuf](https://www.nuget.org/packages/Mappa.Dependency.Protobuf/): methods to map `Google.Protobuf.WellKnownTypes` objects from [Google.Protobuf](https://www.nuget.org/packages/Google.Protobuf) package into common objects.\n- [Mappa Protobuf dependency](https://www.nuget.org/packages/Mappa.Dependency.Protobuf.DependencyInjection/): utility methods to register the Protobuf mapper.\n- [Mappa Bson](https://www.nuget.org/packages/Mappa.Dependency.Bson/): methods to map `MongoDB.Bson` objects from [MongoDB.Bson](https://www.nuget.org/packages/MongoDB.Bson) package into common objects.\n- [Mappa Bson dependency](https://www.nuget.org/packages/Mappa.Dependency.Bson.DependencyInjection/): utility methods to register the Bson mapper.\n\n# 📈 Code coverage history \n- [Code Coverage gist](https://gist.github.com/sanelli/7f4a85bc809328b4821b03125f9190cb)\n- [Code Coverage history](https://gist.github.com/sanelli/7f4a85bc809328b4821b03125f9190cb#file-mappa-code-coverage-history-md)\n\n\u003cimg alt=\"Code coverage history\" src=\"https://gist.githubusercontent.com/sanelli/7f4a85bc809328b4821b03125f9190cb/raw/MAPPA-CODE-COVERAGE-HISTORY.svg\" width=\"800\" height=\"500\"/\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanelli%2Fmappa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsanelli%2Fmappa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanelli%2Fmappa/lists"}