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

Refactoring with .NET 5 Unsafe APIs #3510

Merged
16 commits merged into from
Nov 10, 2020

Conversation

Sergio0694
Copy link
Member

@Sergio0694 Sergio0694 commented Sep 28, 2020

Close #3509

PR Type

What kind of change does this PR introduce?

  • Refactoring (no functional changes, no api changes)

What is the current behavior?

There are a number of usages of Unsafe.AsRef<T>(null) and similar that are verbose.

What is the new behavior?

These occurrences are replaced using the new Unsafe.NullRef<T>() and Unsafe.IsNullRef<T>(...) APIs.

Notes

Leaving this as draft as the new System.Runtime.CompilerServices.Unsafe package is still in release candidate.

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tested code with current supported SDKs
  • Pull Request has been submitted to the documentation repository instructions. Link:
  • Sample in sample app has been added / updated (for bug fixes / features)
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Header has been added to all new source files (run build/UpdateHeaders.bat)
  • Contains NO breaking changes

@Sergio0694 Sergio0694 added improvements ✨ .NET Components which are .NET based (non UWP specific) labels Sep 28, 2020
@Sergio0694 Sergio0694 added this to the 7.0 milestone Sep 28, 2020
@ghost
Copy link

ghost commented Sep 28, 2020

Thanks Sergio0694 for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌

@Sergio0694 Sergio0694 marked this pull request as ready for review October 9, 2020 11:18
@Sergio0694
Copy link
Member Author

Fixed merge conflicts and marked as ready for review, as .NET 5 RC1 is released with "go live" license! 🚀

@Sergio0694
Copy link
Member Author

The 5.0.0 packages are out on NuGet and I've updated this PR, we're good to go! 🚀🚀🚀
Will update all the others and fix conflicts as soon as this one is merged, especially #3356!

@Sergio0694
Copy link
Member Author

Sergio0694 commented Nov 10, 2020

The CI failed with this error:

Test method UnitTests.Helpers.Test_ColorHelper.Test_ColorHelper_ToColor_ScreenColor threw exception:
System.FormatException: Input string was not in a correct format.

I've seen this on and off seemingly at random in a number of failed CI runs across multiple PRs of mine now. My guess is that that crash was caused by the double.Parse calls being used to parse the screen color in the ToColor extension, here:

https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/66be202cbb94413e2fdec35ec5e275e9d9a0e979/Microsoft.Toolkit.Uwp/Helpers/ColorHelper.cs#L94-L97

Basically, whenever the CI happened to run in a server in some region with the decimal specified using , instead of . to separate decimal digits, this would just crash with a FormatException. Fixed it in 63ad9e7 by manually using invariant culture for the parsing calls, that should hopefully stop these crashes from happening in the future and make the method more reliable.

EDIT: all is fine now! 🎉

@ghost
Copy link

ghost commented Nov 10, 2020

Hello @michael-hawker!

Because this pull request has the auto merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 92836d5 into CommunityToolkit:master Nov 10, 2020
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto merge ⚡ improvements ✨ .NET Components which are .NET based (non UWP specific)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor pass with Unsafe.NullRef<T> and Unsafe.IsNullRef<T>
3 participants