次の方法で共有


MVVM Toolkit 警告 MVVMTK0029

包含型がクラス レベルで [NotifyPropertyChangedRecipients] を持っているか継承している場合、[NotifyPropertyChangedRecipients] を持つフィールドに注釈を付ける必要はありません。

次の例では MVVMTK0029 が発生します。

using CommunityToolkit.Mvvm.ComponentModel;

namespace MyApp;

[NotifyPropertyChangedRecipients]
public partial class MyViewModel : ObservableRecipient
{
    // Using [NotifyPropertyChangedRecipients] is redundant here, as the
    // containing type is already annotated with the same attribute.
    [ObservableProperty]
    [NotifyPropertyChangedRecipients]
    public int number;
}

クラス レベルの属性が継承される場合も同様です。

using CommunityToolkit.Mvvm.ComponentModel;

namespace MyApp;

[NotifyPropertyChangedRecipients]
public class MyBaseViewModel : ObservableRecipient
{
}

public partial class MyViewModel : MyBaseViewModel
{
    // Using [NotifyPropertyChangedRecipients] is redundant here, as the
    // containing type is inheriting the same attribute from a base type.
    [ObservableProperty]
    [NotifyPropertyChangedRecipients]
    public int number;
}

その他のリソース

  • 単体テストでは、さらに他の例を見つけることができます。