MADEiN83 / ts-automapper

https://crazydev.fr
8 stars 1 forks source link

Reflection for identical properties #32

Open danielreganuk opened 2 years ago

danielreganuk commented 2 years ago

Are there plans to have true 'AutoMapping' for properties that are identical for both source and destination?

For example:

class Person {
    firstName: string;
    lastName: string;
    dateOfBirth: string;
}

class SourcePerson {
    fullName: string;
    dateOfBirth: string;
}

AutoMapper.create<Person, SourcePerson>('PersonToSourcePerson')
    .map(
        (input) => input.firstName + ' ' + input.lastName,
        (output) => output.fullName
      )

    const sourceObject: Person = {
      firstName: 'John',
      lastName: 'Smith',
      dateOfBirth: '01/01/1990',
    };

const mappedResult = AutoMapper.exec<Person, SourcePerson>('PersonToSourcePerson', sourceObject);

In this case, I would expect my result to show:

{
    fullName: John Smith,
    dateOfBirth: 01/01/1990
}

Instead it is:

{
    fullName: John Smith
}

I can't see this in the todos but from using AutoMapper with .net for many years, it was just an expected result.

Thanks, Dan

MADEiN83 commented 2 years ago

Hi @danielreganuk, Thanks for your interest on this project!

That makes sense! I'll add this feature ASAP.