Replies: 2 comments
-
I considered using a comma public class Person (string Name, string HomeTown), (string Name);
// versus
public class Person (string Name, string HomeTown) | (string Name); I would appreciate thoughts on that or alternative ideas. |
Beta Was this translation helpful? Give feedback.
0 replies
-
This proposal adds language support for something that is likely to be rare. I'd rather see the need for it occurring widely in practice (which I doubt will occur) before considering adding it to the language. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
As mentioned in the current records proposal, it is possible to maintain binary and source compatibility of record types by including compatible implementations of the constructor and members:
Proposal
Removing boilerplate code is a key goals of records. In that spirit, I propose allowing multiple declaration parameter lists in the following manner:
This will produce essentially the
v2
class above. (Note, I believe there are inconsistencies in the above quoted example as compared with the rest of the records proposal. This proposal should be taken as to reflect the final implementation of records.)Here is another example which extends beyond backwards compatibility and provides different parameter lists altogether:
In this case it produces four properties (
Year
,Month
,Day
, andDateTime
) and appropriate boilerplate methods.The pipe character
|
is used to separate parameter lists. The first|
is optional (similar to F# pattern matching syntax).The
with
clause builds from the same syntax structure as in the current proposal. In this case, it is used to specify values for properties defined only in other parameter lists. (default
will be assumed when a property is not specified in the parameter list and is not set viawith
clause.)It is considered an error to specify two parameters in separate parameter lists that have the same name but different types.
Beta Was this translation helpful? Give feedback.
All reactions