次の方法で共有


MVVM Toolkit 警告 MVVMTK0030

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

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

using System.ComponentModel.DataAnnotations;
using CommunityToolkit.Mvvm.ComponentModel;

namespace MyApp;

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

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

using System.ComponentModel.DataAnnotations;
using CommunityToolkit.Mvvm.ComponentModel;

namespace MyApp;

[NotifyDataErrorInfo]
public class MyBaseViewModel : ObservableValidator
{
}

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

その他のリソース

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