Allow omitting type of constructor argument with the same name as field to set that field #2721
Replies: 5 comments
-
At first glance, I see a conflict between this proposal and the very well established naming conventions used for C# code. Method (and constructor) parameters are camelCase. Admittedly, member fields are often camelCase, but lots of people use coding standards with |
Beta Was this translation helpful? Give feedback.
-
Take a look at the Records proposal and the Primary Constructors proposal. |
Beta Was this translation helpful? Give feedback.
-
@canton7 Already seen those but I think they are all overkill when we just sometime want some member to be easily set in constructor. With my proposal it don't need anything but a little compiler magic |
Beta Was this translation helpful? Give feedback.
-
It's probably worth making clear in your proposal why yours is superior to those other two proposals. Records already has a proposal champion in the form of the C# Language PM, and Mads has also written a proposal for primary constructors. Your proposal will need some very, very strong points in its favour to garner more support than those two, and you will need to make those points very clear. |
Beta Was this translation helpful? Give feedback.
-
@canton7 As I said I think both of those is overkill to make a completely whole new syntax and too much restraint for the use case. And it actually not related to my proposal that work on the constructor itself. Not a class It could also use in multiple constructor and could be utilized in all existing codebase that fall into this pattern It also not go against the record or primary constructor too so I don't think it should be concerned about those 2 proposal The primary constructor itself are more likely clashing with records. Why you need to concern about this feature? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Instead of
I think this pattern is very common and could be easily shorthand by compiler
edit : As of concern by @theunrepentantgeek and some other reason. I retract the ability to allow setting property and limit to field only
Beta Was this translation helpful? Give feedback.
All reactions