When I started working on ConsoleExtensions, I made method overloads for every combination of parameter I found reasonable. However, that quickly got out of control. Now I'm ready to work on introducing an options builder so that eventually every feature gets one method that can be configured with an Action<T> delegate. Here's how that works for future reference.
Note optionsAction?.Invoke(options). It might happen that optionsAction is null. This makes sure no null reference exception is thrown and will use the default options in that case.
Note optionsAction?.Invoke(options). It might happen that optionsAction is null. This makes sure no null reference exception is thrown and will use the default options in that case.
string input = ReadLine(options => { options.Prompt = ">"; options.DefaultInput = "Hello, World!"; }); Console.WriteLine(input); static string ReadLine(Action<ReadLineOptions> optionsAction) { ReadLineOptions options = new(); optionsAction?.Invoke(options); return options.DefaultInput; } class ReadLineOptions { public string Prompt { get; set; } = string.Empty; public string DefaultInput { get; set; } = string.Empty; }