Proposal: ref property with both ref getter and setter #8729
Unanswered
BreyerW
asked this question in
Language Ideas
Replies: 0 comments
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.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, you cannot declare something like this:
And for good reason: there is no way to easily disambiguate
Object.testInt=8; //ref getter of setter? both are valid
However, recently there is work to enable ref readonly. This feature should allow to disambiguate ref getter and ref setter like this:
Then in my previous example situation become clear:
Object.testInt=8; //nope, cannot write to getter so resolve to ref setter, if present, error otherwise
.Caveats:
Object.testInt=8;
. Normally setter would be converted to something like this:set_intTest(ref int value)
. This means passing standalone values like8
wont work without workaround.One possible is to generate temporary variable and pass that variable.
wont work.
Possible Workaround: forget about ref benefits and allow only non-ref setter or allow non-ref setter as alternative option to developer (so responsibility is moved to developer).
Maybe someone have another idea?
Things to consider
Allow
in
for setter?Use case
I believe it will mainly have certain benefits to game developers. Consider
Entity
object that consist of Position, Rotation and Scale + all Matrixes:As you can see this would yield massive performance boost in certain scenarios (especially for matrixes, where its normal to have 16 fields) while preserving ability to reliably fire events when one of the properties change.
Beta Was this translation helpful? Give feedback.
All reactions