IssueRaiser

Champion: Readonly members on structs (16.3, Core 3)

# Readonly Instance Methods * [x] Proposed: https://github.com/dotnet/csharplang/blob/master/proposals/csharp-8.0/readonly-instance-members.md * [x] Prototype: Done * [x] Implementation: Done * [ ] Specification: Not Started ## Summary [summary]: #summary Provide a way to specify individual instance members on a struct do not modify state, in the same way that `readonly struct` specifies no instance members modify state. It is worth noting that `readonly instance member` != `pure instance member`. A `pure` instance member guarantees no state will be modified. A `readonly` instance member only guarantees that instance state will not be modified. All instance members on a `readonly struct` could be considered implicitly `readonly instance members`. Explicit `readonly instance members` declared on non-readonly structs would behave in the same manner. For example, they would still create hidden copies if you called an instance member (on the current instance or on a field of the instance) which was itself not-readonly. ## Motivation [motivation]: #motivation Today, users have the ability to create `readonly struct` types which the compiler enforces that all fields are readonly (and by extension, that no instance members modify the state). However, there are some scenarios where you have an existing API that exposes accessible fields or that has a mix of mutating and non-mutating members. Under these circumstances, you cannot mark the type as `readonly` (it would be a brea

Posted by tannergooding on Jul 12, 2018, 9:29 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.4,000 issues0 comments

github (Software)

Champion: Readonly members on structs (16.3, Core 3)

tannergoodingJul 12, 2018, 9:29 PM

# Readonly Instance Methods * [x] Proposed: https://github.com/dotnet/csharplang/blob/master/proposals/csharp-8.0/readonly-instance-members.md * [x] Prototype: Done * [x] Implementation: Done * [ ] Specification: Not Started ## Summary [summary]: #summary Provide a way to specify individual instance members on a struct do not modify state, in the same way that `readonly struct` specifies no instance members modify state. It is worth noting that `readonly instance member` != `pure instance member`. A `pure` instance member guarantees no state will be modified. A `readonly` instance member only guarantees that instance state will not be modified. All instance members on a `readonly struct` could be considered implicitly `readonly instance members`. Explicit `readonly instance members` declared on non-readonly structs would behave in the same manner. For example, they would still create hidden copies if you called an instance member (on the current instance or on a field of the instance) which was itself not-readonly. ## Motivation [motivation]: #motivation Today, users have the ability to create `readonly struct` types which the compiler enforces that all fields are readonly (and by extension, that no instance members modify the state). However, there are some scenarios where you have an existing API that exposes accessible fields or that has a mix of mutating and non-mutating members. Under these circumstances, you cannot mark the type as `readonly` (it would be a brea

Comments (0)

No comments yet. Start the discussion.

Comment on this issue