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

Improved nullability annotations in MVVM Toolkit #4135

Conversation

Sergio0694
Copy link
Member

Contributes to #3873

PR Type

What kind of change does this PR introduce?

  • Improvements

What is the current behavior?

Some helper methods lack some nullability annotations. Specifically:

  • The SetProperty methods directly target a backing field don't indicate that if the supplied input value is not null, then the target field will also always be not null once the method returns (as the two aren't equal).
  • The SetPropertyAndNotifyOnCompletion methods don't indicate that the target TaskNotifier instance will always be not null once the method returns (as the field is always immediately initialized as soon as the method is invoked).

What is the new behavior?

  • Added [NotNullIfNotNull] to mark target fields for SetProperty
  • Added [NotNull] to mark target task notifiers in SetPropertyAndNotifyOnCompletion.

Also had to update the source generator project to ensure the attributes are automatically generated in consuming projects in case they're not available in the compilation, to ensure we don't generate code that will then cause the build to fail. The generator will just bail out early and not do anything if consumers are on .NET Standard 2.1 or above.

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)
  • New major technical changes in the toolkit have or will be added to the Wiki e.g. build changes, source generators, testing infrastructure, sample creation changes, etc...
  • 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) mvvm-toolkit 🧰 Issues/PRs for the Microsoft.Toolkit.Mvvm package next preview ✈️ Label for marking what we want to include in the next preview release for developers to try. labels Jul 27, 2021
@Sergio0694 Sergio0694 added this to the 7.1 milestone Jul 27, 2021
@ghost
Copy link

ghost commented Jul 27, 2021

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 🙌

@ghost ghost requested review from michael-hawker, azchohfi and Rosuavio July 27, 2021 15:28
@Sergio0694 Sergio0694 force-pushed the improvement/mvvmtoolkit-annotations branch from 30b0383 to a6a15dc Compare July 30, 2021 00:14
@michael-hawker michael-hawker merged commit 0f744f8 into CommunityToolkit:main Aug 2, 2021
@Sergio0694 Sergio0694 deleted the improvement/mvvmtoolkit-annotations branch August 2, 2021 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvements ✨ mvvm-toolkit 🧰 Issues/PRs for the Microsoft.Toolkit.Mvvm package .NET Components which are .NET based (non UWP specific) next preview ✈️ Label for marking what we want to include in the next preview release for developers to try.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants