public static void Main()
Person tom = new Person("Tom", 35);
Person bob = new Person("Bob", 16);
bool tomIsValid = ValidateUser(tom);
bool bobIsValid = ValidateUser(bob);
Console.WriteLine($"Результат валидации Тома: {tomIsValid}");
Console.WriteLine($"Результат валидации Боба: {bobIsValid}");
bool ValidateUser(Person person)
Type type = typeof(Person);
object[] attributes = type.GetCustomAttributes(false);
foreach (Attribute attr in attributes)
if (attr is AgeValidationAttribute ageAttribute)
return person.Age >= ageAttribute.Age;
class AgeValidationAttribute : Attribute
public AgeValidationAttribute()
public AgeValidationAttribute(int age) => Age = age;
public string Name { get; }
public int Age { get; set; }
public Person(string name, int age)