`RaisePropertyChanged` method in `ObservableObject`

Aperta
#1,086 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
csharp

Direzione di ricerca

Individua l’implementazione di ObservableObject e i test o punti di ingresso esistenti di PropertyChanged. Confronta il comportamento proposto di RaisePropertyChanged e OnPropertyChanged, quindi verifica che il percorso diretto di generazione dell’evento funzioni senza invocare gli override e che i test pertinenti passino.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

feature request :mailbox_with_mail:
Overview

Trying to replace an internal, legacy implementation of ObservableCollection with the one in CommunityToolkit it was noticed there is no way to simply raise the PropertyChanged event without invoking OnPropertyChanged and any overrides.

This functionality is relied upon in some cases and it's time consuming to work around. Since it seems harmless adding upstream here to ObservableObject I created this ticket.

API breakdown
class ObservableObject
{
    protected void RaisePropertyChanged([CallerMemberName] string? propertyName = null)
    {
        PropertyChanged?.Invoke(new PropertyChangedEventArgs(propertyName));
    }

    protected void OnPropertyChanged(PropertyChangedEventArgs e)
    {
        PropertyChanged?.Invoke(e);
    }
}
Usage example

The cases where this is most useful are those where you are doing something within an OnPropertyChanged override and want to raise some event manually (you just calculated something manually). If you use OnPropertyChanged again it's going to crash with a stack overflow as it keeps calling itself. Of course you can guard against this but it seems easy enough just to support the ability to raise the event directly. Tooling should generally let you do what you want to do while guiding towards a proper flow. Not restrict you completely.

Breaking change?

No

Alternatives

None in this context. Would just have to force all code to work with OnPropertyChanged only.

Additional context

No response

Help us help you

No, just wanted to propose this

Lingua principale
C#
Stelle
3.8k
Fork
402
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di CommunityToolkit/dotnet

Tutte le issue di CommunityToolkit/dotnet

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.