Add the `partial` modifier to the generated property of the Relay Command
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- csharp
调研方向
首先定位 Relay Command 的源代码生成入口点,并将其生成属性的处理方式与 Observable Property 生成器进行比较。验证生成的命令属性支持匹配的手写 partial 声明,并且 XAML/App Model 源代码生成场景能够在编译时无需反射地解析它。
由索引模型根据 Issue 内容生成。
描述
Overview
Add the partial modifier to the generated property of the Relay Command.
Now, app models like .NET MAUI have introduced a source generation feature that allows XAML to be translated into C#. However, the issue remains that source generators cannot interact with one another, such that only handwritten code is accessible.
Since the Observable Property is partial, it can be referenced in XAML without any issues. However, the Relay Command property is not partial, which prevents XAML source generation from inferring it. To resolve this, update the generated Relay Command property partial so that its declaration can be added in the handwritten code, while the MVVM toolkit handles the implementation.
API breakdown
Providing the source-generated code for reference. The generated property needs to be partial.
User code:
public partial IRelayCommand IncrementCommand { get; }
Generated:
private global::CommunityToolkit.Mvvm.Input.RelayCommand? incrementCommand;
// The request is make this IncrementCommand property partial
// so that the developer can add a declaration part in the source type.
public global::CommunityToolkit.Mvvm.Input.IRelayCommand IncrementCommand => incrementCommand ??= new global::CommunityToolkit.Mvvm.Input.RelayCommand(new global::System.Action(Increment));
Usage example
The IncrementCommand is now visible to the App Model source generator.
Previously, the evaluation occurred at runtime; now, to support AOT, it is resolved at compile time. To avoid reflection, the C# expression API is used, requiring at least the declaration/definition to be part of the handwritten code.
<Button Command="{Binding IncrementCommand}" />
Breaking change?
I'm not sure
Alternatives
Manually create the command property, losing all the toolkit's benefits.
Additional context
Multiple source generators at work.
Help us help you
No, just wanted to propose this
- 主要语言
- C#
- 星标
- 3.8k
- 派生
- 403
- 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 于 87 天前认领。 未关闭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
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
bug priority: P2
难度 1/5 1 小时以内 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
IridiumIO/CompactGUI#699 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 73/100
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复