« Mapster » : différence entre les versions
De Banane Atomic
Aller à la navigationAller à la recherche
Aucun résumé des modifications |
|||
Ligne 10 : | Ligne 10 : | ||
// update itemDto with data from item | // update itemDto with data from item | ||
item.Adapt(itemDto); | item.Adapt(itemDto); | ||
</kode> | |||
= [https://github.com/MapsterMapper/Mapster/wiki/Configuration Configuration] = | |||
<kode lang='cs'> | |||
TypeAdapterConfig<Item, ItemDto> // src, dest | |||
.NewConfig() // create new map config (overwrite existing ones) | |||
.ForType() // OR create a map config if no one exists, otherwise append to th existing one | |||
.Ignore(dest => dest.Prop1) // do not map Prop1 | |||
.Map(dest => dest.Prop2, src => $"{0} {1}", src.Prop2, src.Prop3)); // custom mapping for Prop2 | |||
</kode> | </kode> | ||
Version du 1 juillet 2023 à 20:50
Links
Mapping
// create a new itemDto from item var itemDto = item.Adapt<ItemDto>(); // update itemDto with data from item item.Adapt(itemDto); |
Configuration
TypeAdapterConfig<Item, ItemDto> // src, dest .NewConfig() // create new map config (overwrite existing ones) .ForType() // OR create a map config if no one exists, otherwise append to th existing one .Ignore(dest => dest.Prop1) // do not map Prop1 .Map(dest => dest.Prop2, src => $"{0} {1}", src.Prop2, src.Prop3)); // custom mapping for Prop2 |
Installation
dotnet add package Mapster |