« Mapster » : différence entre les versions

De Banane Atomic
Aller à la navigationAller à la recherche
Aucun résumé des modifications
Aucun résumé des modifications
 
(4 versions intermédiaires par le même utilisateur non affichées)
Ligne 2 : Ligne 2 :
= Links =
= Links =
* [https://github.com/MapsterMapper/Mapster Mapster on GitHub]
* [https://github.com/MapsterMapper/Mapster Mapster on GitHub]
* [https://github.com/MapsterMapper/Mapster/wiki Mapster wiki on GitHub]
= Mapping =
<kode lang='cs'>
// create a new itemDto from item
var itemDto = item.Adapt<ItemDto>();
// update itemDto with data from item
item.Adapt(itemDto);
</kode>
= [https://github.com/MapsterMapper/Mapster/wiki/Configuration Configuration] =
<kode lang='cs'>
// global config
TypeAdapterConfig.GlobalSettings.Default.IgnoreNullValues(true);
// config the mapping from Item to ItemDto
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>
= [https://github.com/MapsterMapper/Mapster/wiki/Dependency-Injection Dependency Injection] =


= Installation =
= Installation =

Dernière version du 15 juillet 2023 à 12:16

Links

Mapping

Cs.svg
// create a new itemDto from item
var itemDto = item.Adapt<ItemDto>();

// update itemDto with data from item
item.Adapt(itemDto);

Configuration

Cs.svg
// global config
TypeAdapterConfig.GlobalSettings.Default.IgnoreNullValues(true);

// config the mapping from Item to ItemDto
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

Dependency Injection

Installation

Bash.svg
dotnet add package Mapster