Novos atributos em Data annotation | .NET 8 | CSharp
- Novos atributos em Data annotation | .NET 8 | CSharp Attributes
Novos atributos | Base64String, AllowedValues, DeniedValues
using System;
using System.ComponentModel.DataAnnotations;
public class UserDto
{
// Field value is a well-formed Base64 string.
[Base64String]
public string AccessToken { get; set; } = default!;
// List of values that should be allowed in a property.
[AllowedValues(1, 2, 8, 23, 55)]
public uint Grade { get; set; }
// List of values that should not be allowed in a property.
[DeniedValues(1, 2, 3, 4, 5)]
public uint Age { get; set; }
// Specifies the minimum and maximum length of collection/string
// data allowed in a property.
[Length(7, 25)]
public string FirstName { get; set; } = default!;
// Struct does not equal its default value.
[Required(DisallowAllDefaultValues = true)]
public Guid Id { get; set; }
}