[MVVM] `AttachedProperty`/`DirectProperty`/`StyledProperty` source generators
还没有人认领这个 Issue。
评估
调研方向
先从 API 分解和 QuxControl.cs 使用示例开始,然后将提议的生成输出与现有的 toolkit 结构进行比较。issue 没有列出任何实现文件或测试,因此第一项任务是定位 source-generator 的入口点和相关测试项目。支持这三个 attribute,并生成所示的 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 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
CommunityToolkit/dotnet 的其他 Issue
-
RelayCommand<T>.CanExecute(null) returns false for value types without a predicate可能已有人在做 @apachezy 于 85 天前认领。 未关闭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 一周以上 新手友好度 35/100
CommunityToolkit/dotnet#1217 ·
-
bug :bug:
难度 3/5 1-2 天 新手友好度 68/100
CommunityToolkit/dotnet#1215 ·
查看 CommunityToolkit/dotnet 的全部 Issue
相似的 Issue
-
bug priority: P2
难度 1/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 77/100
维护者通常 1 天内回复
-
[Docs] README/PRIVACY still name AppCenter although v1.5.6.0+ uses the Microsoft Store Services SDK未关闭
难度 2/5 1-3 小时 新手友好度 78/100
-
needs-triage
难度 2/5 1-3 小时 新手友好度 72/100
Azure/azure-sdk-tools#17317 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 66/100
swisstopo/swissgeol-boreholes-suite#3086 ·
维护者通常 1 天内回复