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

Make structs readonly #1130

merged 2 commits into from May 20, 2018

Make structs readonly #1130

merged 2 commits into from May 20, 2018


Copy link

@jskeet jskeet commented May 19, 2018

This is the first pass at #1033.

Once #1129 is merged, this is a single commit.

IXmlSerializable is fundamentally broken for readonly structs, but we can cast away the readonly-ness using the System.Runtime.CompilerServices.Unsafe package. It feels like the benefits of this are greater than the downsides.

Copy link

LGTM. Are there any threading or 'undefined behaviour'-style issues with the use of Unsafe.AsRef()?

Copy link
Member Author

jskeet commented May 20, 2018

Basically we're breaking the readonly contract, with all the fun that could entail. If this is used by anyone outside regular XML serialization, I'd expect problems. Within XML serialization, it should be fine - this it all called on new objects.

I'm going to wait until we've got the first benchmarks working for v3 before merging.

@jskeet jskeet merged commit 0ffe6da into nodatime:master May 20, 2018
@jskeet jskeet deleted the readonly-attempt branch May 20, 2018 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants