1 import std.exception : 2 assertThrown, 3 enforce; 4 5 struct Tester 6 { 7 @Validate!(value => enforce(value == 1)) 8 int a = 1; 9 10 @Validate!((value, options) => enforce(value == 2 * options.a)) 11 int b = 2; 12 13 string[] calls; 14 15 @PostValidate(Priority.low) 16 void priorityLow() { 17 calls ~= "priorityLow"; 18 } 19 20 @PostValidate(Priority.medium) 21 void priorityMedium() { 22 calls ~= "priorityMedium"; 23 } 24 25 @PostValidate(Priority.high) 26 void priorityHigh() { 27 calls ~= "priorityHigh"; 28 } 29 } 30 31 Tester options; 32 33 options = processOptions(options); 34 35 assert(options.calls == [ 36 "priorityHigh", 37 "priorityMedium", 38 "priorityLow", 39 ]); 40 41 options.a = 2; 42 43 assertThrown!Exception(processOptions(options));
Call this method on the result of parseArgs to execute validations and validation hooks.