Incorrect partial method prototypes for generated observable properties
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 62/100
Piste de recherche
Commencez par la reproduction sur .NET 9 avec CommunityToolkit.Mvvm 8.4.0, en comparant les déclarations générées de partial methods pour le champ et la propriété [ObservableProperty]. Vérifiez les prototypes de OnChanging et OnChanged, en particulier le paramètre nullable oldValue ; c’est terminé lorsque les deux formes correspondent et que CS8826 est absent.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Describe the bug
When decorating a property of a reference or otherwise nullable type with [ObservableProperty] the two-argument partial property-changing and property-changed method prototypes are generated differently than for decorated fields, not considering that the oldValue argument may be null.
Regression
No response
Steps to reproduce
- Create a new project targeting .NET 9.0 and depending on CommunityToolkit.Mvvm
- Create a class inheriting from
ObservableObject - Add the following code to the class:
[ObservableProperty] private object _testA; [ObservableProperty] public object TestB { get; set; } partial void OnTestAChanged(object? oldValue, object newValue) { /* do nothing */ } partial void OnTestBChanged(object? oldValue, object newValue) { /* do nothing */ } - Note that
OnTestBChangedhas warning CS8826 on it, because the generated partial declaration ispartial void OnTestBChanged(global::System.Object oldValue, global::System.Object newValue);but there's no such warning forOnTestAChanged.
Expected behavior
The OnChanging(oldValue,newValue) and OnChanged(oldValue,newValue) partial method declarations for properties decorated with ObservablePropertyAttribute will be generated the same as for fields decorated with same.
Screenshots
No response
IDE and version
VS 2022
IDE version
17.14.9
Nuget packages
- CommunityToolkit.Common
- CommunityToolkit.Diagnostics
- CommunityToolkit.HighPerformance
- CommunityToolkit.Mvvm (aka MVVM Toolkit)
Nuget package version(s)
8.4.0
Additional context
The oldValue argument should always be generated as nullable for reference types as the initial call to the methods may be due to setting the property in the constructor (e.g. initial value may be based on a constructor argument, or the change methods may be used to set up and remove event handlers on the property value).
Help us help you
No, just wanted to report this
- Langage dominant
- C#
- Étoiles
- 3.8k
- Forks
- 400
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de CommunityToolkit/dotnet
-
RelayCommand<T>.CanExecute(null) returns false for value types without a predicatePeut-être pris @apachezy l’a pris il y a 122 jours. Ouvertebug :bug:
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
CommunityToolkit/dotnet#1206 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
CommunityToolkit/dotnet#1186 ·
-
bug :bug:
Difficulté 1/5 Moins d'une heure Accessibilité débutants 68/100
CommunityToolkit/dotnet#648 ·
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 20/100
CommunityToolkit/dotnet#1218 ·
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 35/100
CommunityToolkit/dotnet#1217 ·
Toutes les issues de CommunityToolkit/dotnet
Issues similaires
-
Scaffold marks an association as required when its composite foreign key has a nullable columnOuvertearea: scaffold status: needs-tests
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
Les mainteneurs répondent en général sous 1 jour
-
provider:flagd type:fix
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
open-feature/dotnet-sdk-contrib#789 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 1/5 1-3 heures Accessibilité débutants 72/100
NimblePros/Metronome#23 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
jsboige/CoursIA#28504 · 3 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
要トリアージ
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
Les mainteneurs répondent en général sous 1 jour