Incorrect partial method prototypes for generated observable properties
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 62/100
Direzione di ricerca
Inizia con la riproduzione in .NET 9 usando CommunityToolkit.Mvvm 8.4.0, confrontando le dichiarazioni generate dei partial methods per il campo e la proprietà [ObservableProperty]. Verifica i prototipi di OnChanging e OnChanged, in particolare il parametro nullable oldValue; il lavoro è completato quando entrambe le forme corrispondono e CS8826 è assente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- C#
- Stelle
- 3.8k
- Fork
- 402
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di CommunityToolkit/dotnet
-
RelayCommand<T>.CanExecute(null) returns false for value types without a predicateForse già presa @apachezy l’ha presa 121 giorni fa. Apertabug :bug:
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
CommunityToolkit/dotnet#1206 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
CommunityToolkit/dotnet#1186 ·
-
bug :bug:
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100
CommunityToolkit/dotnet#648 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 20/100
CommunityToolkit/dotnet#1218 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
CommunityToolkit/dotnet#1217 ·
Tutte le issue di CommunityToolkit/dotnet
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 2 giorni
-
area: core bug help wanted ready
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
ZaidX88/sluice#265 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
rate limit at lrclib.netAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
-
area: remote bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Install a C# EnvironmentAperta📅 Sprint 4 Module-Tools Setup Submit:None 🦔 Size Tiny
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
CodeYourFuture/Module-Tools#712 ·