Skip to content

Instantly share code, notes, and snippets.

@jtheisen
Created April 30, 2026 07:43
Show Gist options
  • Select an option

  • Save jtheisen/9fd51d51171d66fa0a3c3ea45c405d71 to your computer and use it in GitHub Desktop.

Select an option

Save jtheisen/9fd51d51171d66fa0a3c3ea45c405d71 to your computer and use it in GitHub Desktop.
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;
}
}
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