File: Models\ValidationProviderAttributeModel.cs
Web Access
Project: src\src\Mvc\test\WebSites\FormatterWebSite\FormatterWebSite.csproj (FormatterWebSite)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
 
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc.DataAnnotations;
 
namespace FormatterWebSite;
 
public class ValidationProviderAttributeModel
{
    [FirstName]
    public string FirstName { get; set; }
 
    [StringLength(maximumLength: 5)]
    [LastName]
    public string LastName { get; set; }
}
 
public class FirstNameAttribute : ValidationProviderAttribute
{
    public override IEnumerable<ValidationAttribute> GetValidationAttributes()
    {
        return new List<ValidationAttribute>
            {
                new RequiredAttribute(),
                new RegularExpressionAttribute(pattern: "[A-Za-z]*"),
                new StringLengthAttribute(maximumLength: 5)
            };
    }
}
 
public class LastNameAttribute : ValidationProviderAttribute
{
    public override IEnumerable<ValidationAttribute> GetValidationAttributes()
    {
        return new List<ValidationAttribute>
            {
                new RequiredAttribute()
            };
    }
}