GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Configuration Configuration
Matthias Beerens edited this page
There are two ways of configuring the options. using MatthiWare.CommandLine; static int Main(string[] args) { var parser = new CommandLineParser<OptionsModel>(); parser.Configure(opt => opt.Message) .Name("m", "message") .Required(); parser.Configure(opt => opt.Port) .Name("p", "port") .Default(8080); var result = parser.Parse(args); if (result.HasErrors) { Console.Error.WriteLine(result.Error); Console.ReadKey(); return -1; } var options = result.Result; Console.WriteLine($"Message: {options.Message}"); Console.WriteLine($"Port: {options.Port}"); Console.ReadKey(); return 0; } public class OptionsModel { public string Message { get; set; } // Mandatory public int Port { get; set; } // Optional } using MatthiWare.CommandLine; static int Main(string[] args) { var parser = new CommandLineParser<OptionsModel>(); var result = parser.Parse(args); if (result.HasErrors) { Console.Error.WriteLine(result.Error); Console.ReadKey(); return -1; } var options = result.Result; Console.WriteLine($"Message: {options.Message}"); Console.WriteLine($"Port: {options.Port}"); Console.ReadKey(); return 0; } public class OptionsModel { [Required, Name("m", "message")] public string Message { get; set; } // Mandatory [Name("p", "port"), DefaultValue(8080)] public int Port { get; set; } // Optional } Fluent API will overwrite attributes. Clone this wiki locally |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |