包含型がクラス レベルで [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;
}
その他のリソース
- 単体テストでは、さらに他の例を見つけることができます。
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
MVVM Toolkit