Proposal: Auto properties with custom setters #8561
Unanswered
silver-sd
asked this question in
Language Ideas
Replies: 2 comments 6 replies
-
See: #140 |
Beta Was this translation helpful? Give feedback.
3 replies
-
It was intended for customizing properties by SourceGenerators (the simplest way to pass the property code for SG). Currently available implementation:
This would look better:
This one doesn't look better than using functions:
|
Beta Was this translation helpful? Give feedback.
3 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.
-
If the 'implicit' keyword is specified, the property declaration has only a single body, which is executed after the property's backing field has changed.
The compiler generates the following code for this syntax:
If the 'explicit' keyword is specified, the field assignment must be made manually.
The compiler generates this:
If the getter and setter have different access modifiers, the modifier placed after the "implicit" keyword applies to the setter:
public implicit protected Type PropertyName {}
The compiler generates this:
There are two options that differ only by "field = value;", but both are necessary.
The 'implicit' option is expected to be used in most scenarios. It enhances code readability.
However, if actions are sometimes needed before the assignment "field = value;", having two options helps to avoid completely rewriting the code.
Beta Was this translation helpful? Give feedback.
All reactions