Practice ยท 2 of 3
Attribute-driven validation
CHALLENGE
Difficulty: advanced+25 XP
Define attribute RangeAttribute : Attribute with int Min; int Max; (usage: properties). Implement static List<string> Validate(object obj): for each instance property with a RangeAttribute whose value is an int outside [Min,Max], add "Name" of the property to the result. Return failures in declaration order. Classes to support: Account { [Range(1,120)] public int Age; [Range(0,100)] public int Score; } (fields, not properties โ support both fields and properties).
Press Submit to check your solution.
Back to lesson: Practice: Reflection drills