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

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