mapper icon indicating copy to clipboard operation
mapper copied to clipboard

@AutoMap() as class decorator

Open thaindq opened this issue 3 years ago • 2 comments

Is your feature request related to a problem? Please describe.

I usually find myself adding @AutoMap decorator to every or most of the properties of a class.

Describe the solution you'd like

I think it would be handy if @AutoMap can be applied to class level instead of each property in that case. We can also add @AutoMapIgnore() (property decorator) to skip unwanted ones.

Describe alternatives you've considered

No response

Additional context

No response

thaindq avatar Sep 19 '22 23:09 thaindq

Hi @thaindq, thank you for the suggestion.

ClassDecorator was my first thought when I first started working on AutoMapper. However, ClassDecorator doesn't have information of its properties :(

I'm open to any suggestion to make AutoMap less painful.

nartc avatar Sep 20 '22 11:09 nartc

Hi, yeah unfortunately, but I was thinking maybe it could at least work as default mapping without any options or type information. For example:

@AutoMap()
class A {
    // Automatically add @AutoMap() here
    prop1!: string;
    // Automatically add @AutoMap() here
    prop2!: string;
    // Automatically add @AutoMap() here
    prop3!: string;
    // Automatically add @AutoMap() here
    prop4!: string;

    @AutoMap(() => B) // Need it here for B type
    prop5! B;
    
    @IgnoreAutoMap()
    prop6!: string;
}

So at least we don't have to use decorator on every properties. I haven't checked if this is possible with class decorator yet but if it isn't then I guess I'll have to stick with the current way.

thaindq avatar Sep 22 '22 00:09 thaindq

This is not possible as ClassDecorator does not have information of the members.

nartc avatar Mar 10 '23 05:03 nartc