-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
C# 8 has added a new feature called "readonly members". This feature allows you to indicate that an individual method on a non-readonly struct is itself "readonly" (i.e. that the method does not mutate the state of the instance).
Edit
We need to define a strategy for if/how/when/where this feature should be used across the .NET Libraries. Originally, the intent of this issue was to take a pass over the libraries and annotate methods on non-readonly structs which do not and will never mutate the state of the instance. It was noted that there are a number of these methods in the System.Numerics namespace which users also may try to pass around as in. However, after such a pass was taken by @hrrrrustic in #46675, we realized that we need to be more strategic about this effort.
Some of the aspects that need to be considered are:
- For every API touched, we have to evaluate it through the lens of whether we'd ever want to allow mutation to occur -- it would be a breaking change to remove
readonlylater. For example, adding caching to areadonlymethod later would be a breaking change. - How we quantify the value that
readonlyprovides across different areas relative to that possibility - If we can define and document API design guidance to follow both with these PRs and for all APIs going forward