Skip to main content

Practice · 2 of 3

Bind JSON into Options

CHALLENGE
Difficulty: intermediate+25 XP

Bind a JSON section into a typed options class with defaults: missing keys keep defaults, present keys override, and Validate() reports ALL problems (not just the first) by throwing OptionsValidationException with the message "Retry: <all problems joined by '; '>". ``csharp public sealed class RetryOptions { public int MaxAttempts { get; set; } = 3; public int DelayMs { get; set; } = 200; } public sealed class OptionsBinder { public static RetryOptions Bind(string json); // { "Retry": { ... } } public static void Validate(RetryOptions options); // MaxAttempts >= 1, DelayMs >= 0 } ``

Back to lesson: Practice: Config Practice: Providers, Binding, Secrets