record BarEntity(Guid Id, string Value);
record BarDto(Guid Id, string Value);
class BarMappingProfile : OneWayProfile<BarEntity, BarDto>
{
}
record FooEntity(Guid Id, string Value);
record FooDto(Guid Id, string Value);
class FooMappingProfile : TwoWayProfile<FooEntity, FooDto>
{
}
class TransactionEntity
{
public int Id { get; set; }
public Guid OperatorId { get; set; }
public DateTimeOffset ProcessedAt { get; set; }
public double Amount { get; set; }
}
class TransactionDto
{
public int Id { get; set; }
public long ProcessedAt { get; set; }
public double Amount { get; set; }
}
class TransactionMappingProfile : TwoWayProfile<TransactionEntity, TransactionDto>
{
public override void ConfigureLeftToRightMapping()
{
CreateMap<TransactionEntity, TransactionDto>()
.ForMember(
dto => dto.Id,
options => options.MapFrom(entity => entity.Id))
.ForMember(
dto => dto.ProcessedAt,
options => options.MapFrom(entity => entity.ProcessedAt.ToUnixTimeMilliseconds()))
.ForMember(
dto => dto.Amount,
options => options.MapFrom(entity => entity.Amount));
}
public override void ConfigureRightToLeftMapping()
{
CreateMap<TransactionDto, TransactionEntity>()
.ForMember(
entity => entity.Id,
options => options.MapFrom(dto => dto.Id))
.ForMember(
entity => entity.OperatorId,
options => options.Ignore())
.ForMember(
entity => entity.ProcessedAt,
options => options.MapFrom(dto => DateTimeOffset.FromUnixTimeMilliseconds(dto.ProcessedAt)))
.ForMember(
entity => entity.Amount,
options => options.MapFrom(dto => dto.Amount));
}
}
AceCSharp.StructuredAutoMapper is Copyright © 2023 Dimitrie Tataru and other contributors under the MIT license.