[MVVM] `AttachedProperty`/`DirectProperty`/`StyledProperty` source generators
まだ誰も着手していません。
評価
調査の方向性
API の内訳と QuxControl.cs の使用例から始め、その後、提案された生成出力を既存の toolkit の構造と比較します。issue には実装ファイルやテストが記載されていないため、最初の作業は source-generator のエントリポイントと関連するテストプロジェクトを見つけることです。3 つの属性をサポートし、示されている property メンバーと Avalonia property メンバーを生成できれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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 はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
CommunityToolkit/dotnet のほかの issue
-
RelayCommand<T>.CanExecute(null) returns false for value types without a predicate対応中かも @apachezy が 86 日前に担当しました。 オープンbug :bug:
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
CommunityToolkit/dotnet#1206 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
CommunityToolkit/dotnet#1186 ·
-
bug :bug:
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
CommunityToolkit/dotnet#648 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
CommunityToolkit/dotnet#1217 ·
-
bug :bug:
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
CommunityToolkit/dotnet#1215 ·
CommunityToolkit/dotnet の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
gavin-wolfe/wolfden#104 ·
メンテナーはふだん 1 日以内に返信
-
[BUG] Still libmicrohttpd dependency is not removed properly from External-Dependency-Info.txt fileオープンtype/bug
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
[辞書] かんそうりつ->乾燥率オープン辞書
難易度 1/5 1時間未満 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
bug good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
thomhurst/TUnit#7201 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
ArduPilot/MissionPlanner#3826 ·
メンテナーはふだん 1 日以内に返信