Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[MVVM] `AttachedProperty`/`DirectProperty`/`StyledProperty` source generators

Aperta
#1,203 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
csharp
Ambito
tooling

Direzione di ricerca

Inizia con l’analisi dell’API e l’esempio di utilizzo di QuxControl.cs, quindi confronta l’output generato proposto con la struttura esistente del toolkit. L’issue non indica file di implementazione né test, quindi il primo compito è individuare i punti di ingresso del source-generator e i progetti di test pertinenti. Il lavoro è completo quando sono supportati i tre attributi e vengono prodotti i membri property e Avalonia property mostrati.

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

Descrizione

feature request :mailbox_with_mail:
Overview

Examples like these require a considerable amount of repetitive code:

public bool Foo
{
  get => GetValue(FooProperty);
  set => SetValue(FooProperty, value);
}

public ObservableCollection<BarViewModel>? BarsSource
{
  get => GetValue(BarsSourceProperty);
  set => SetValue(BarsSourceProperty, value);
}

public ICommand? BazCommand
{
  get => GetValue(BazCommandProperty);
  set => SetValue(BazCommandProperty, value);
}

public static readonly StyledProperty<bool> FooProperty =
  AvaloniaProperty.Register<QuxControl, bool>(nameof(Foo));

public static readonly StyledProperty<ObservableCollection<BarViewModel>?> BarsSourceProperty =
  AvaloniaProperty.Register<QuxControl, ObservableCollection<BarViewModel>?>(nameof(BarsSource));

public static readonly StyledProperty<ICommand?> BazCommandProperty =
  AvaloniaProperty.Register<QuxControl, ICommand?>(nameof(BazCommand));
API breakdown
namespace CommunityToolkit.Mvvm.ComponentModel;

[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
public sealed class AttachedPropertyAttribute : Attribute;

[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
public sealed class DirectPropertyAttribute : Attribute;

[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
public sealed class StyledPropertyAttribute : Attribute;
Usage example

QuxControl.cs

public partial class QuxControl : Panel
{
  [StyledProperty]
  public partial bool Foo { get; set; }

  [StyledProperty]
  public partial ObservableCollection<BarViewModel>? BarsSource { get; set; }

  [StyledProperty]
  public partial ICommand? BazCommand { get; set; }
}

MyProject.Views.QuxControl.g.cs

namespace MyProject.Views
{
  partial class QuxControl
  {
    /* ... */
    public partial bool Foo
    {
      get => GetValue(FooProperty);
      set => SetValue(FooProperty, value);
    }

    /* ... */
    public partial ObservableCollection<BarViewModel>? BarsSource
    {
      get => GetValue(BarsSourceProperty);
      set => SetValue(BarsSourceProperty, value);
    }

    /* ... */
    public partial ICommand? BazCommand
    {
      get => GetValue(BazCommandProperty);
      set => SetValue(BazCommandProperty, value);
    }

    /* ... */
    public static readonly StyledProperty<bool> FooProperty =
      AvaloniaProperty.Register<QuxControl, bool>(nameof(Foo));

    /* ... */
    public static readonly StyledProperty<ObservableCollection<BarViewModel>?> BarsSourceProperty =
      AvaloniaProperty.Register<QuxControl, ObservableCollection<BarViewModel>?>(nameof(BarsSource));

    /* ... */
    public static readonly StyledProperty<ICommand?> BazCommandProperty =
      AvaloniaProperty.Register<QuxControl, ICommand?>(nameof(BazCommand));
  }
}
Breaking change?

No

Alternatives

There are existing packages (https://github.com/jp2masa/Avalonia.PropertyGenerator, https://github.com/lucdem/AvaSourceGenerators) that don't entirely work in the proposed way.

Additional context

No response

Help us help you

No, just wanted to propose this

Lingua principale
C#
Stelle
3.8k
Fork
401
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.