Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging two objects into a new target instance #1416

Open
SunnyVachhetA opened this issue Jul 25, 2024 · 1 comment
Open

Merging two objects into a new target instance #1416

SunnyVachhetA opened this issue Jul 25, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@SunnyVachhetA
Copy link

Describe the bug
In records, with property having get; init; is not creating update mapping in generated source code. Due to init; setter.
We are using init due to coding standards.

Declaration code

public class Car
{
    public int Id { get; set; }
		
    public string Name { get; set; }
		
    public double? Price { get; set; }
}

public record CarDto
{
    public int Id { get; init; }
		
    public string Name { get; init; }
		
    public double Price { get; init; }
}

[Mapper]
public partial class CarMapper
{
    public partial void UpdateCarDto(Car car, CarDto carDto);
}

Actual relevant generated code

// Actual relevant code generated by Mapperly
// <auto-generated />
#nullable enable
public partial class CarMapper
{
    [global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "3.6.0.0")]
    public partial void UpdateCarDto(global::Car car, global::CarDto carDto)
    {
    }
}

Expected relevant generated code

// The generated code how you expect it to look like
#nullable enable
public partial class CarMapper
{
    [global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "3.6.0.0")]
    public partial void UpdateCarDto(global::Car car, global::CarDto carDto)
    {
        return carDto with
        {
            Id = car.Id,
            Name = car.Name,
            Price = car.Price ?? existingCarDto.Price
        };
    }
}

Environment (please complete the following information):

  • Mapperly Version: 3.6.0
  • Nullable reference types: Enabled
  • .NET Version: .NET 8.0.100
  • Target Framework: .NET 8.0.0
  • Compiler Version: '4.8.0-3.23524.11 (f43cd10b)'.
  • C# Language Version: 12.0
  • IDE: Visual Studio 17.5.4
  • OS: Windows 11

Additional context

@SunnyVachhetA SunnyVachhetA added the bug Something isn't working label Jul 25, 2024
@latonz
Copy link
Contributor

latonz commented Jul 29, 2024

This is not really a bug, it‘s a not supported feature by Mapperly: Merging two objects into a new target instance.

@latonz latonz added enhancement New feature or request and removed bug Something isn't working labels Jul 29, 2024
@latonz latonz changed the title Mapping Issue with Record Property with init Merging two objects into a new target instance Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants