Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C#: Implement readonly-ness in Array and Dictionary #71986

Merged
merged 1 commit into from
Jan 27, 2023

Conversation

raulsntos
Copy link
Member

@raulsntos raulsntos commented Jan 24, 2023

  • Implement support for setting Arrays as readonly
    • Added to Core in Implement read-only arrays #61127.
    • Expose IsReadOnly property that checks the read_only ptr in the engine array.
    • Add MakeReadOnly method.
      • There's precedent in System.Text.Json for a method MakeReadOnly that makes the JsonSerializerOptions readonly, there's no way to make it writable again.
    • Calls that mutate the Array when it's read-only will throw an InvalidOperationException like other read-only collections in .NET.
  • Implement support for setting Dictionaries as readonly
    • Added to Core in Implement read-only dictionaries. #61087.
    • Expose IsReadOnly property that checks the read_only ptr in the engine dictionary.
    • Add MakeReadOnly method.
      • Just like with Array, it makes the collection immutable but cannot make it mutable again after that.
    • Calls that mutate the Dictionary when it's read-only will throw an InvalidOperationException like other read-only collections in .NET.

@raulsntos
Copy link
Member Author

raulsntos commented Jan 27, 2023

This is pending changes to Core that may requisite changing the implementation of this PR (see #71845 (comment)).

Edit: Changes made, following the merge of #71845.

- Expose `IsReadOnly` and add `MakeReadOnly` method.
@raulsntos raulsntos force-pushed the dotnet/readonly-collections branch from 5cc24ee to 1aa5414 Compare January 27, 2023 14:25
@raulsntos raulsntos marked this pull request as ready for review January 27, 2023 14:28
@raulsntos raulsntos requested a review from a team as a code owner January 27, 2023 14:28
@akien-mga akien-mga merged commit 6462e54 into godotengine:master Jan 27, 2023
@akien-mga
Copy link
Member

Thanks!

@raulsntos raulsntos deleted the dotnet/readonly-collections branch January 27, 2023 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants