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

Invalid mapping to exists class if source is object #524

Open
heggi opened this issue Jan 12, 2023 · 6 comments
Open

Invalid mapping to exists class if source is object #524

heggi opened this issue Jan 12, 2023 · 6 comments
Assignees
Labels

Comments

@heggi
Copy link

heggi commented Jan 12, 2023

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?

@andrerav
Copy link
Contributor

Possibly related to #485

@DocSvartz
Copy link

DocSvartz commented Sep 30, 2023

@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

@DocSvartz
Copy link

DocSvartz commented Oct 18, 2023

@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. :)

@DocSvartz
Copy link

DocSvartz commented Oct 18, 2023

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

@DocSvartz
Copy link

DocSvartz commented Oct 20, 2023

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 :)

@andrerav
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants