-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Guard APIs for .NET Standard 2.1 #3167
Guard APIs for .NET Standard 2.1 #3167
Conversation
@michael-hawker Thank you for the guidance with the merge, it worked! 😄🎉 |
@michael-hawker Added those overloads for |
@azchohfi I can't find your old comment, we good? |
@michael-hawker All resolved. |
Follow up to #3131 (separate PR to keep things simpler).
PR Type
What kind of change does this PR introduce?
What is the current behavior?
The
Guard
APIs are in theMicrosoft.Toolkit
project, that currently only targets .NET Standard 2.0. This makes it necessary to always reference theSystem.Memory
package, and it makes it impossible to decorate APIs with the new C# 8 nullability/flow attributes from .NET Core 3.0. This also results in a worse coding experience, as the code analysis tool don't have all the info it needs when invoking some calls (eg.Guard.IsNotNull
won't notify it that the input variable will never benull
afterwards).What is the new behavior?
This PR makes a few changes, which don't alter the functionality at all or the API surface area. They're just changes in the project structure and code decorations. In particular:
Microsoft.Toolkit
System.Memory
package only necessary when targeting .NET Standard 2.0. On .NET Standard 2.1, only theSystem.Runtime.CompilerServices.Unsafe
package is referenced.[NotNull]
and[DoesNotReturnWhen]
) on some of theGuard
APIsHere's a screenshot showing the difference in the code analysis info when using the .NET Standard 2.0 and 2.1 versions of the same
Guard.IsNotNull
API (with the new attributes):PR Checklist
Please check if your PR fulfills the following requirements:
Pull Request has been submitted to the documentation repository instructions. Link:Sample in sample app has been added / updated (for bug fixes / features)Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/windows-toolkit/WindowsCommunityToolkit-design-assets)