Get-only properties are emitted as readonly in CoreFx ref assemblies
See original GitHub issueGet-only properties are generated as readonly properties when auto-generating ref
assemblies. The autogeneration steps are as mentioned in updating-ref-source.md. This causes multiple changes in the ref assembly code; not sure if it is legit and should be accepted.
E.g.
- public bool AllowTrailingCommas { get { throw null; } set { } }
- public System.Text.Json.JsonCommentHandling CommentHandling { get { throw null; } set { } }
+ public bool AllowTrailingCommas { readonly get { throw null; } set { } }
+ public System.Text.Json.JsonCommentHandling CommentHandling { readonly get { throw null; } set { } }
And another one with subtle difference
- public System.Buffers.ReadOnlySequence<byte> ValueSequence { get { throw null; } }
- public System.ReadOnlySpan<byte> ValueSpan { get { throw null; } }
+ public readonly System.Buffers.ReadOnlySequence<byte> ValueSequence { get { throw null; } }
+ public readonly System.ReadOnlySpan<byte> ValueSpan { get { throw null; } }
Entire diff can be found here.
Creating this issue based on discussion in dotnet/corefx/issues/36125 in following comments, _@WinCPP in https://github.com/dotnet/corefx/issues/36125#issuecomment-500109703_ _@ahsonkhan in https://github.com/dotnet/corefx/issues/36125#issuecomment-500173705_
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Is "readonly" meaningful on a getter-only ref struct property ...
So, yes, readonly is meaningful. I think the case where readonly is redundant only when the struct itself is already declared as readonly...
Read more >How can I have read-only properties in my ...
Yes, it is possible to create read-only properties in Entity Framework (EF) classes. One way to achieve this is to use the private...
Read more >Allow ref-returning get-only auto-properties #15623
The reality is that this feature should have been accompanied by readonly and some way to block the copying of user defined value...
Read more >readonly vs. private getter-only property in C# 6
Both provide read-only access to a list that is initialised when an instance of the class is created. It's possible that it creates...
Read more >Declare and Initialize Read-only Auto Properties in C# | ...
In the case of a field member, you get only one chance to initialize the field with a value, and that is when...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The drawbacks are just the same as not having the attribute, there are some cases which may still have hidden copies due to how the compiler handles things. This is more a concern about the implementation within a member marked
readonly
though, and in that you will get an compiler error if you try to invoke a non-readonly method (which just forces you to create an explicit copy).Also, to summarize what @ahsonkhan asked me offline.
Thanks @tannergooding for the info. Closing this issue as discussed above.