5.2k sao GitHub và vẫn tăng — MapsterMapper/Mapster là dự án C# mà TopGit đang theo dõi trên nền tảng. A fast, fun and stimulating object to object Mapper
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Mapster creates the destination object and maps values to it.
var destObject = sourceObject.Adapt<Destination>();
Mapping to an existing object
You create the object, Mapster maps to the object.
sourceObject.Adapt(destObject);
Use Mapster with Dependency Injection
You can get your IMapper instance via dependency injection, so you do not have to change code, when migrating to mapster from automapper!
Just add Mapster to service collection:
services.AddMapster();
And use it with DI in your Project:
public class Test
{
public Test(IMapper mapper)
{
var sourceObject = mapper.Adapt<Destination>();
}
}
Queryable Extensions
Mapster also provides extensions to map queryables.
using (MyDbContext context = new MyDbContext())
{
// Build a Select Expression from DTO
var destinations = context.Sources.ProjectToType<Destination>().ToList();
// Versus creating by hand:
var destinations = context.Sources.Select(c => new Destination {
Id = c.Id,
Name = c.Name,
Surname = c.Surname,
....
})
.ToList();
}
Generating models & mappers
No need to write your own DTO classes. Mapster provides Mapster.Tool to help you generating models. And if you would like to have explicit mapping, Mapster also generates mapper class for you.
[AdaptTo("[name]Dto"), GenerateMapper]
public class Student {
...
}
Then Mapster will generate for you:
public class StudentDto {
...
}
public static class StudentMapper {
public static StudentDto AdaptToDto(this Student poco) { ... }
public static StudentDto AdaptTo(this Student poco, StudentDto dto) { ... }
public static Expression<Func<Student, StudentDto>> ProjectToDto => ...
}
Mapster was designed to be efficient on both speed and memory. The repository includes a benchmark project in src/Benchmark that compares the local Mapster build, its compiler variants, and other modern mapping libraries like AutoMapper, Mapperly, and Facet.
Roslyn Compiler
FEC
Code generation
Facet
Mapperly
The snapshot below shows the FlatTypes scenario (Person -> PersonDTO), a best-case DTO with simple property-to-property mapping and no nested objects or collections.
[!NOTE]
More complex object shapes can change the relative results. See the complete benchmark results for ComplexTypes, RecursiveTypes, and TotalAllTypes.
Method
MapOperations
Mean
StdDev
Error
Ns/Map
Ratio
Gen0
Allocated
Alloc Ratio
Bytes/Map
Mapster 10.0.8
1000000
6.849 ms
0.6851 ms
1.0358 ms
6.849
1.01
4781
76.29 MB
1.00
80
Mapster 10.0.8 (Roslyn)
1000000
6.579 ms
0.2782 ms
0.4206 ms
6.579
0.97
4781
76.29 MB
1.00
80
Mapster 10.0.8 (FEC)
1000000
6.549 ms
0.9130 ms
1.3803 ms
6.549
0.97
4781
76.29 MB
1.00
80
Mapster 10.0.8 (Codegen)
1000000
5.868 ms
0.3266 ms
0.5488 ms
5.868
0.86
4781
76.29 MB
1.00
80
AutoMapper 14.0.0
1000000
29.645 ms
0.8963 ms
1.5062 ms
29.645
4.37
4750
76.29 MB
1.00
80
Facet 6.5.5
1000000
7.801 ms
1.0231 ms
1.5467 ms
7.801
1.15
8601
137.33 MB
1.80
144
Facet 6.5.5 (Compiled Projection)
1000000
5.508 ms
0.7064 ms
1.0679 ms
5.508
0.81
4781
76.29 MB
1.00
80
Mapperly 4.3.1
1000000
6.521 ms
0.8369 ms
1.2652 ms
6.521
0.96
4781
76.29 MB
1.00
80
Step into debugging
Step-into debugging lets you debug your mapping and inspect values just like your code.
Code Generation
Code generation allows you to
Validate mapping at compile time
Getting raw performance
Seeing your mapping code & debugging
Finding usage of your models' properties
There are currently two tools which you can choose based on your preferences.
Mapster.Tool NEW!
TextTemplate
Change logs
https://github.com/MapsterMapper/Mapster/releases
Usage Guides with Translations
English
中文文档 (sp thx to @staneee)
Acknowledgements
JetBrains kindly provides Mapster with a free open-source licence for their Resharper and Rider.
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/MapsterMapper/Mapster là nguồn chính thức.
MapsterMapper/Mapster có bao nhiêu sao?
MapsterMapper/Mapster có 5.2k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/MapsterMapper/Mapster. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
MapsterMapper/Mapster có phải mã nguồn mở không?
Có — MapsterMapper/Mapster phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/MapsterMapper/Mapster.
MapsterMapper/Mapster có trang demo không?
Dự án có trang chủ ở http://mapstermapper.github.io/Mapster/. Tab "Readme" ở trang này thường có ảnh chụp và hướng dẫn bắt đầu nhanh.
MapsterMapper/Mapster là gì?
MapsterMapper/Mapster (MapsterMapper/Mapster) là dự án C# trên GitHub. Theo mô tả gốc: A fast, fun and stimulating object to object Mapper
Đọc đầy đủ README ở tab phía trên.
Mapster có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về Mapster.