Error MVVMTK0015 when the desired NotifyPropertyChangedFor property is an explicit interface implementation
まだ誰も着手していません。
評価
調査の方向性
まず、提供された明示的なインターフェイス実装を 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 ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
CommunityToolkit/dotnet のほかの issue
-
RelayCommand<T>.CanExecute(null) returns false for value types without a predicate対応中かも @apachezy が 79 日前に担当しました。 オープン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 が 16 日前に担当しました。 オープンfeature request :mailbox_with_mail:
難易度 5/5 1週間以上 初心者へのやさしさ 45/100
CommunityToolkit/dotnet#1214 ·
CommunityToolkit/dotnet の issue をすべて見る
似ている issue
-
python triage
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
microsoft/semantic-kernel#14590 ·
メンテナーはふだん 3 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
nkdAgility/azure-devops-migration-tools#3226 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
Status: New
難易度 1/5 1時間未満 初心者へのやさしさ 80/100
dnnsoftware/Dnn.Platform#7556 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信