Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Error MVVMTK0015 when the desired NotifyPropertyChangedFor property is an explicit interface implementation

オープン
#1,114 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
csharp
領域
devtools

調査の方向性

まず、提供された明示的なインターフェイス実装を CommunityToolkit.Mvvm 8.4.0 で再現し、MVVMTK0015 を生成する NotifyPropertyChangedFor 検証を追跡します。サンプルの動作を確認してから、明示的に実装されたインターフェイスプロパティが受け入れられるように検証を更新し、既存の無効な対象では引き続き診断が報告されるようにします。

索引モデルが issue の本文から書いたものです。

説明

bug :bug:
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:

  1. There is a public property named Enabled, it's simply of lessened visibility (only visible through the interface)
  2. 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 はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

CommunityToolkit/dotnet のほかの issue

CommunityToolkit/dotnet の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。