Add [MemberNotNull] on [ObservableProperty] setter when needed #645
Labels
feature request 📬
A request for new changes to improve functionality
mvvm-toolkit 🧰
Issues/PRs for the MVVM Toolkit
Overview
Currently,
[ObservableProperty]
has an issue with nullability annotations. Consider this:Even if you set
Name
in the constructor, you'll get a warning saying "name might be null", as the compiler doesn't know that settingName
(to a non null value) also meansname
is set to a non null value. We can fix this by generating:That is, if:
[MemberNotNull]
is availableThen also add
[MemberNotNull]
in the setter, referring the field.This way you can set the property in the constructor, and Roslyn will no longer warn that the field might be null and it's not set.
Usage example
The following should not produce a warning:
Breaking change?
No
The text was updated successfully, but these errors were encountered: