Allow invoking readonly members on structs in object initializers #8427
Replies: 2 comments 45 replies
-
This seems like a case for |
Beta Was this translation helpful? Give feedback.
-
This code doesn't make sense to me. Numbers property is a getter for a ref struct. How would you even be able to write that to a class? It's illegal even without CS1918. It seems that you would want to have a collection expression work by adding elements to an existing collection, rather than creating a new one. I don't think that even makes sense with the assignment operator, and maybe needs something like a backward pipe operator |
Beta Was this translation helpful? Give feedback.
-
Imagine you have a lazy-instantiated collection, and a "proxy collection" to wrap around it:
The gist of it is, the CS1918 shouldn't be generated, because the
Wrapper.Add
isreadonly
, therefore it's safe to invoke it as part of collection initializer. CS1918 should continue to be generated in all other existing cases.Beta Was this translation helpful? Give feedback.
All reactions