Permit Constructor to pass Getter-Only Auto-Properties to methods with 'out', 'ref', or 'in' modifiers. #2695
Unanswered
Ken-Clement
asked this question in
Language Ideas
Replies: 1 comment
-
Not necessarily opposed to this idea, but:
This change would be trading one inconsistency for another. You can't ever pass any properties by reference. Setting a get-only auto property in a constructor is implemented by the compiler as setting the backing field directly, so it should at least be somewhat simple to do what you're asking for. Here are some related suggestions to add this capability for properties in general: |
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.
Uh oh!
There was an error while loading. Please reload this page.
-
Constructors allow Getter-Only Auto-Properties to be assigned. This is explained here as:
As a consequence, such a getter-only auto-property should also be usable in a method call as a parameter having an 'out', 'ref', or 'in' modifier.
Such a capability would be particularly useful when constructing an immutable object whose getter-only property values are computed in the constructor by a framework using fluent syntax with methods having 'out' parameters to capture intermediate results of the fluent computation.
This is possible now by using local variables to capture these 'out' values and assigning the local variables to the getter-only properties. However, this is the very sort of boilerplate clutter that auto-properties were created to eliminate.
On the surface, this does not seem as though it would be particularly difficult to do and it would eliminate what is arguably an inconsistency in the language and make a desirable implementation pattern elegant. I will examine the Roslyn source to validate this and even attempt such a modification.
Beta Was this translation helpful? Give feedback.
All reactions