Created
April 30, 2026 07:43
-
-
Save jtheisen/9fd51d51171d66fa0a3c3ea45c405d71 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class CustomerToFaithfulCustomerDto : Mapping<FaithfulOrderDto, Order> | |
| { | |
| public override void Fill(FaithfulOrderDto target, Order source) | |
| { | |
| target.Total = source.Total; | |
| target.Customer = With<CustomerToCustomerDto>().Map(source.Customer); | |
| } | |
| } | |
| public class CustomerToCustomerDto : Mapping<CustomerDto, Customer> | |
| { | |
| public override void Fill(CustomerDto target, Customer source) | |
| { | |
| target.Name = source.Name; | |
| } | |
| } | |
| public class OrderToFlatOrderDto : Mapping<FlatOrderDto, Order> | |
| { | |
| public override void Fill(FlatOrderDto target, Order source) | |
| { | |
| target.Total = source.Total; | |
| target.CustomerName = source.Customer?.Name; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public abstract class Mapping<TDestination, TSource> | |
| where TDestination : new() | |
| { | |
| public abstract void Fill(TDestination target, TSource source); | |
| public TMapping With<TMapping>() | |
| where TMapping : new() | |
| { | |
| return new TMapping(); | |
| } | |
| public TDestination Map(TSource source) | |
| { | |
| var target = new TDestination(); | |
| Fill(target, source); | |
| return target; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment