Edit

Share via


NotifyDataErrorInfoAttribute Class

Definition

An attribute that can be used to support ObservablePropertyAttribute in generated properties, when applied to partial properties contained in a type that is inheriting from ObservableValidator and using any validation attributes. When this attribute is used, the generated property setter will also call ValidateProperty(Object, String). This allows generated properties to opt-in into validation behavior without having to fallback into a full explicit observable property.

This attribute can be used as follows:

partial class MyViewModel : ObservableValidator
{
    [ObservableProperty]
    [NotifyDataErrorInfo]
    [Required]
    [MinLength(2)]
    public partial string Username { get; set; }
}

And with this, code analogous to this will be generated:
partial class MyViewModel
{
    public partial string Username
    {
        get => field;
        set => SetProperty(ref field, value, validate: true);
    }
}
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false, Inherited=false)]
public sealed class NotifyDataErrorInfoAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false, Inherited=false)>]
type NotifyDataErrorInfoAttribute = class
    inherit Attribute
Public NotInheritable Class NotifyDataErrorInfoAttribute
Inherits Attribute
Inheritance
NotifyDataErrorInfoAttribute
Attributes

Remarks

This attribute can also be used on a class, which will enable the validation on all generated properties contained in it.

Just like ObservablePropertyAttribute, this attribute can also be used on fields as well.

Applies to