mapper
mapper copied to clipboard
@AutoMap() as class decorator
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
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.
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.
This is not possible as ClassDecorator does not have information of the members.