Skip to content

Invalid mapping to exists class if source is object #524

Description

@heggi
public class Source
{
    public int X1 { get; set; }
}
public class Dest
{
    public int X1 { get; set; }
}

var source = new Source { X1 = 123 };
var dest = new Dest { X1 = 321 };
var dest1 = source.Adapt(dest);
Console.WriteLine($"{dest.X1} {dest1.X1} {dest.GetHashCode()} {dest1.GetHashCode()}");

result: 123 123 19575591 19575591, dest and dest1 are the same object

void somemap(object source)
{
    var dest = new Dest { X1 = 321 };
    var dest1 = source.Adapt(dest);

    Console.WriteLine($"{dest.X1} {dest1.X1} {dest.GetHashCode()} {dest1.GetHashCode()}");
}

var source = new Source { X1 = 123 };
somemap(source);

result: 321 123 32001227 19575591
dest not changed, dest1 is a new object.

Any ideas? Why if source is object, Adapt create a new instance of dest class?

Activity

  1. andrerav commented on Jan 29, 2023

    @andrerav
    Member

    Possibly related to #485

  2. self-assigned this
    on Jan 29, 2023
  3. added a commit that references this issue on Sep 24, 2023
  4. DocSvartz commented on Sep 30, 2023

    @DocSvartz
    Contributor

    @andrerav @heggi

    Typeof(TSource) always return Type as Object. Need use dynamic or Cast to Runtime Type before Adapt

    What happens is this:
    Adapt this for Object -> TDistination -> TDistination

    In this case use special overload from (it work) :

    var dest1 = source.Adapt(dest, source.GetType(), dest.GetType());

    But a new instance is when the TDistination is detection as Record #537

  5. DocSvartz commented on Oct 18, 2023

    @DocSvartz
    Contributor

    @andrerav @heggi

    I get fix it, but this
    Null propagation for primitive types broke down. By the end of the week this problem will most likely be resolved. :)

  6. DocSvartz commented on Oct 18, 2023

    @DocSvartz
    Contributor

    Any ideas? Why if source is object, Adapt create a new instance of dest class?

    This Adapt Source from object to type of TDestination == source.Adapt<TDestination>()

    ObjectAdapter not created Update function

  7. added a commit that references this issue on Oct 18, 2023
  8. DocSvartz commented on Oct 20, 2023

    @DocSvartz
    Contributor

    Hello @heggi can you provide additional samples for testing?
    My fantasy is over, I can’t think of anything else that can be tested in this case :)

    Hello, @andrerav fixing of this Issue ready for review #645 . I managed to finish it a little faster than the end of the week :)

  9. andrerav commented on Oct 20, 2023

    @andrerav
    Member

    Thank you @DocSvartz, I will review it later today! :)

  10. added a commit that references this issue on Jan 3, 2025
  11. stagep commented on Jan 7, 2025

    @stagep

    In order to identify issues that are still active, we are closing issues that we believe are either resolved or are dormant. If your issue is still active then please reopen. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions