Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン
#1,203 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
静か
技術スタック
csharp
領域
tooling

調査の方向性

API の内訳と QuxControl.cs の使用例から始め、その後、提案された生成出力を既存の toolkit の構造と比較します。issue には実装ファイルやテストが記載されていないため、最初の作業は source-generator のエントリポイントと関連するテストプロジェクトを見つけることです。3 つの属性をサポートし、示されている property メンバーと Avalonia property メンバーを生成できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
C#
スター
3.8k
フォーク
401
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

CommunityToolkit/dotnet のほかの issue

CommunityToolkit/dotnet の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。