Commander icon indicating copy to clipboard operation
Commander copied to clipboard

Allow mapping input to public properties [updated].

Open ratiw opened this issue 10 years ago • 3 comments

Sometimes when we have a DTO class which will contain a lot of properties (more than 5 or 6 properties), it does not do any good defining all those properties in the constructor.

This PR will allow mapping input to the "public properties" instead of using the constructor.

ratiw avatar Jul 28 '14 15:07 ratiw

I'd like to have this option as well (I ran into a case where I had 36 constructor parameters...).

One thing that I think you could improve is that it should be a little more strict to match the same behavior as if it were constructor parameters:

  • Throw an exception when attributes are passed through that don't exist as properties on the command.
  • Throw an exception when properties which are defined on the command are missing from the attributes.

What do you think?

stidges avatar Jul 30 '14 17:07 stidges

@stidges Well, I think that can be done. I just initially thought it is unnecessary so the code I wrote only maps the inputs to the existing public properties only. I'll try to make it more strict and consistent with the original code. Thanks for the comment, anyway. :)

ratiw avatar Jul 31 '14 15:07 ratiw

@stidges Now, the mapInputToCommandProperties() should throw an exception when any public property is not present in the input, so it behaves more like it constructor counterpart. By the way, any other input that is/are not defined in the command (DTO) will be ignored.

ratiw avatar Jul 31 '14 17:07 ratiw