Error MVVMTK0015 when the desired NotifyPropertyChangedFor property is an explicit interface implementation
还没有人认领这个 Issue。
评估
调研方向
首先使用 CommunityToolkit.Mvvm 8.4.0 重现提供的显式接口实现,并跟踪产生 MVVMTK0015 的 NotifyPropertyChangedFor 验证。确认示例的行为,然后更新验证,使显式实现的接口属性能够被接受,同时现有的无效目标仍然报告该诊断。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
A compilation error results for a situation that we think should be valid. Specifically:
error MVVMTK0015: The target(s) of [NotifyPropertyChangedFor] must be a (different) accessible property, but "(the notify-for property name)" has no (other) matches in type (my type) (https://aka.ms/mvvmtoolkit/errors/mvvmtk0015)
It appears that the toolkit's conditions for NotifiyPropertyChangedFor are not satisfied when the property exists only as an explicitly-implemented interface property.
Regression
No response
Steps to reproduce
Given this simplified reproduction:
public interface IMenuItem
{
bool Enabled { get; }
}
public partial class MenuItem : ObservableObject, IMenuItem
{
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(IMenuItem.Enabled))]
public partial int ValueThatAffectsEnabled { get; set; }
bool IMenuItem.Enabled => ValueThatAffectsEnabled > 0;
}
Compiling results in the following error:
error MVVMTK0015: The target(s) of [NotifyPropertyChangedFor] must be a (different) accessible property, but "Enabled" has no (other) matches in type MenuItem (https://aka.ms/mvvmtoolkit/errors/mvvmtk0015)
Expected behavior
We expect this to be allowed by the NotifyPropertyChangedFor attribute's validation because:
- There is a public property named
Enabled, it's simply of lessened visibility (only visible through the interface) - It is a very common for our views to work with their View Models as interfaces, not concrete types. This lets us swap in/out compatible view model types.
We can work around this:
- We could make those properties not explicit interface implementations (we'd rather not, we design member visibility very intentionally).
- We could add OnXXXXChanged() partial methods to manually call
OnPropertyChanged("the desired property").
but it would be better if the library would allow this.
Screenshots
No response
IDE and version
VS 2022
IDE version
17.14.10
Nuget packages
- CommunityToolkit.Common
- CommunityToolkit.Diagnostics
- CommunityToolkit.HighPerformance
- CommunityToolkit.Mvvm (aka MVVM Toolkit)
Nuget package version(s)
8.4.0
Additional context
No response
Help us help you
No, just wanted to report 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 于 83 天前认领。 未关闭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 ·
-
bug :bug:
难度 3/5 1-2 天 新手友好度 68/100
CommunityToolkit/dotnet#1215 ·
-
Add segmented buffering and sequence reads to `ArrayPoolBufferWriter<T>`可能已有人在做 @paulomorgado 于 21 天前认领。 未关闭feature request :mailbox_with_mail:
难度 5/5 一周以上 新手友好度 45/100
CommunityToolkit/dotnet#1214 ·
查看 CommunityToolkit/dotnet 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
dette technique priorité: basse zone: service
难度 2/5 1-3 小时 新手友好度 68/100
damiensabau/nexus-lobby#25 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
sebastienros/jint#4282 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 76/100
pyrevitlabs/pyRevit#3792 ·
维护者通常 1 天内回复
-
clawsweeper:needs-product-decision clawsweeper:needs-security-review clawsweeper:no-new-fix-pr clawsweeper:source-repro impact:security impact:ux-friction issue-rating: 🦞 diamond lobster P2
难度 2/5 1-3 小时 新手友好度 75/100
openclaw/openclaw-windows-node#1763 · 1 条评论 · 1 个 reaction ·
维护者通常 1 天内回复