Class NotDefaultAttribute
Namespace: AdCodicem.ValueObjects.Annotations
Assembly: AdCodicem.ValueObjects.Abstractions.dll
Requires a value-object member not to hold the instance equal to default(TSelf), which
[AttributeUsage(AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Parameter, AllowMultiple = false)]
public sealed class NotDefaultAttribute : ValidationAttribute
Inheritance
object ← Attribute ← ValidationAttribute ← NotDefaultAttribute
Inherited Members
ValidationAttribute.FormatErrorMessage(string), ValidationAttribute.GetValidationResult(object?, ValidationContext), ValidationAttribute.IsValid(object?), ValidationAttribute.Validate(object?, ValidationContext), ValidationAttribute.Validate(object?, string), ValidationAttribute.ErrorMessage, ValidationAttribute.ErrorMessageResourceName, ValidationAttribute.ErrorMessageResourceType, ValidationAttribute.RequiresValidationContext, Attribute.Equals(object?), Attribute.GetCustomAttribute(Assembly, Type), Attribute.GetCustomAttribute(Assembly, Type, bool), Attribute.GetCustomAttribute(MemberInfo, Type), Attribute.GetCustomAttribute(MemberInfo, Type, bool), Attribute.GetCustomAttribute(Module, Type), Attribute.GetCustomAttribute(Module, Type, bool), Attribute.GetCustomAttribute(ParameterInfo, Type), Attribute.GetCustomAttribute(ParameterInfo, Type, bool), Attribute.GetCustomAttributes(Assembly), Attribute.GetCustomAttributes(Assembly, bool), Attribute.GetCustomAttributes(Assembly, Type), Attribute.GetCustomAttributes(Assembly, Type, bool), Attribute.GetCustomAttributes(MemberInfo), Attribute.GetCustomAttributes(MemberInfo, bool), Attribute.GetCustomAttributes(MemberInfo, Type), Attribute.GetCustomAttributes(MemberInfo, Type, bool), Attribute.GetCustomAttributes(Module), Attribute.GetCustomAttributes(Module, bool), Attribute.GetCustomAttributes(Module, Type), Attribute.GetCustomAttributes(Module, Type, bool), Attribute.GetCustomAttributes(ParameterInfo), Attribute.GetCustomAttributes(ParameterInfo, bool), Attribute.GetCustomAttributes(ParameterInfo, Type), Attribute.GetCustomAttributes(ParameterInfo, Type, bool), Attribute.GetHashCode(), Attribute.IsDefaultAttribute(), Attribute.IsDefined(Assembly, Type), Attribute.IsDefined(Assembly, Type, bool), Attribute.IsDefined(MemberInfo, Type), Attribute.IsDefined(MemberInfo, Type, bool), Attribute.IsDefined(Module, Type), Attribute.IsDefined(Module, Type, bool), Attribute.IsDefined(ParameterInfo, Type), Attribute.IsDefined(ParameterInfo, Type, bool), Attribute.Match(object?), Attribute.TypeId, object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()
Remarks
A null passes, so that an absent TSelf? is TSelf? holding the default instance is refused. The check reads
OrderId.Create(Guid.Empty), is refused too, as FluentValidation's
NotDefault refuses it. A member that is no value object throws VO0041 reports at compile time, and so does a collection of value objects, whose elements are not checked.
A refusal is a The {0} field is required., so that an answer reads the same
whichever refused. ValueObject.value_object.required, {0} the member, as FluentValidation's NotDefault does.
The type is found in the registry, or described by reflection where the runtime supports dynamic code: under native AOT, a value object written by hand and a construction of a generic one are registered by hand first.
Constructors
NotDefaultAttribute()
Creates the attribute, whose message is The {0} field is required..
public NotDefaultAttribute()
Methods
FormatErrorMessage(string)
Applies formatting to an error message, based on the data field where the error occurred.
public override string FormatErrorMessage(string name)
Parameters
name string
The name to include in the formatted message.
Returns
An instance of the formatted error message.
Remarks
The message DataAnnotations formats on its own, outside a validation: with
Exceptions
The current attribute is malformed.
IsValid(object?, ValidationContext)
Validates the specified value with respect to the current validation attribute.
protected override ValidationResult? IsValid(object? value, ValidationContext validationContext)
Parameters
value object?
The value to validate.
validationContext ValidationContext
The context information about the validation operation.
Returns
An instance of the
Exceptions
The current attribute is malformed.
The member is no value object, or its type is not a value object the registry describes.