Auto Implemented Primary Constructors #10037
-
|
Hey All, Primary constructors are great, and have helped reduce a lot of boilerplate, especially for service injection. One thing that I do from time to time is creating a service based on another service, with some small changes. Sometimes this is better handled by encapsulating the given service, but sometimes it is more compact to inherit the original service and extend it. For cases where I'm doing that, at the moment, I use this: What would be nice (I think :P ) would be if the compiler could auto handle the primary constructors like so: And use the _ as a marker to simply replicate the properties from the given base classes primary constructor. Now.. I'm sure there's a heap more to think about, but just throwing it out there, is this something that anyone else would find useful? Are there a bunch of dragons lurking in that syntax? This could work if there was just one constructor as well, even if the base wasn't a primary one.. but I can also see that this would explode if the base had multiple constructors, in that case, I'd expect a compile error and it would be time to get perpendicular, er, specific :) Cheers -Mike |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
#9958