AutoConstructor icon indicating copy to clipboard operation
AutoConstructor copied to clipboard

Add addParameterless option, fix spelling

Open DomasM opened this issue 1 year ago • 4 comments

Add addParameterless option - implement https://github.com/k94ll13nn3/AutoConstructor/issues/119

:this() call calling generated parameterless constructor is never emmited because:

  • that wouldn't achieve anything as there is no code in this constructor
  • generated constructor is marked as obsolete to avoid direct, so code would not compile
Anything to inject? addParameterless Generation result
No False Analyzer error
No True Only empty ctor
Yes False Ctor with arguments
Yes True Two ctors: empty and with arguments

changelog:

## [5.4.0] - 2024-05-21

### Added

- Add `addParameterless` option on `AutoConstructor` attribute to generate parameterless constructor for serialization use.
- Add analyzer for base type parameterless constructor existence  when using `addParameterless` option

DomasM avatar May 20 '24 10:05 DomasM

Thanks, I will take a look this week. Just so you know, the CHANGELOG is automatically generated from the Github releases so your changes will be overridden.

k94ll13nn3 avatar May 20 '24 19:05 k94ll13nn3

I think that options must be provided to

  • remove the obsolete attribute if wanted
  • customize the obsolete message

I don't want this package to be linked to "serialization", and generating a parameterless constructor can be useful outside this context so this should be possible.

k94ll13nn3 avatar May 21 '24 06:05 k94ll13nn3

can we do this via project level settings:

AutoConstructor_MarkParameterlessConstructorAsObsolete (bool) AutoConstructor_ParameterlessConstructorObsoleteMessage (string)

and what are the default values then?

specifying these options with every [AutoConstructor] attribute usage would be as much boilerplate as just writing the constructor itself without any generator.

DomasM avatar May 21 '24 07:05 DomasM

can we do this via project level settings:

AutoConstructor_MarkParameterlessConstructorAsObsolete (bool) AutoConstructor_ParameterlessConstructorObsoleteMessage (string)

Yes that is what I was thinking

and what are the default values then?

specifying these options with every [AutoConstructor] attribute usage would be as much boilerplate as just writing the constructor itself without any generator.

The default can be what you already defined (so true for the obsolete and the comment that you already made).

k94ll13nn3 avatar May 21 '24 07:05 k94ll13nn3

Added these two options as discussed.

DomasM avatar May 21 '24 11:05 DomasM

I agree that passing around a boolean flag is not very elegant - here is an alternative implementation by having two different methods https://github.com/DomasM/AutoConstructor/commit/01f475580a6492bff7490e387284a5952fa9cd62 if this is preferred, I can amend that commit to this branch

DomasM avatar May 21 '24 20:05 DomasM

It's ok, you can leave it like it is. I will try merge it and release it before the end of the week.

k94ll13nn3 avatar May 22 '24 06:05 k94ll13nn3

noticed that addDefaultBaseAttribute option is not handled correctly, added test and moved to separate generation methods

DomasM avatar May 22 '24 11:05 DomasM