Skip to content

MapWith() and MapToTargetWith() are ignored when ShallowCopyForSameType is set #628

@rafalka

Description

@rafalka

When ShallowCopyForSameType then custom conversion defined by MapWith() or MapToTargetWith() is ignored

Sample code (based on existing UT with added ShallowCopyForSameType config)

      [TestMethod]
      public void MapToTargetWith_Should_Work_With_Adapt_To_Target()
      {
          var a = new Foo { A = 1 };
          var b = new Bar { A = 2 };

          //This will not work as expected => b.A will be 1, ignoring the mapping defined
          var config = new TypeAdapterConfig();
          config.Default.ShallowCopyForSameType(true);

          config.NewConfig<double, double>().MapToTargetWith((x, y) => 5);
          a.Adapt(b, config);
          b.A.ShouldBe(5);
      }

      internal class Foo
      {
          public double A { get; set; }
      }

      internal class Bar
      {
          public double A { get; set; }
      }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions