CommandLine.Parser.ParseArguments C# (CSharp) Method

ParseArguments() public static method

Parses a System.String array of command line arguments, setting values read in options parameter instance.
Thrown if is null. Thrown if is null.
public static ParseArguments ( string args, object options ) : bool
args string A array of command line arguments.
options object An instance to receive values. /// Parsing rules are defined using derived types.
return bool
        public static bool ParseArguments(string[] args, object options)
        {
            return parser.ParseArguments(args, options);
        }

Same methods

Parser::ParseArguments ( string args, object options, TextWriter helpWriter ) : bool

Usage Example

Example #1
0
        private static void Main(string[] args)
        {
            var parser = new Parser(config => config.HelpWriter = Console.Out);
            if (args.Length == 0)
            {
                parser.ParseArguments<Options>(new[] { "--help" });
                return;
            }

            Options options = null;
            parser.ParseArguments<Options>(args)
                  .WithParsed(r => { options = r; });

            if (string.IsNullOrEmpty(options.Job))
            {
                Console.WriteLine("Job required!");
                return;
            }

            Console.WriteLine(options.Job);
            switch (options.Job.ToLower())
            {
                case "sqlread":
                    SqlBenchmark.ReadAsync(options.Parallel).Wait();
                    break;

                case "migrate":
                    Sql2MongoMigrator.MigrateAsync().Wait();
                    break;

                case "read":
                    MongoDbBenchmark.ReadAsync(options.Parallel).Wait();
                    break;

                case "duplicate":
                    MongoDbBenchmark.DuplicateAsync(options.Parallel).Wait();
                    break;

                case "replace":
                    MongoDbBenchmark.ReplaceAsync(options.Parallel).Wait();
                    break;

                case "savesimple":
                    MongoDbBenchmark.SaveSimpleAsync(options.Parallel).Wait();
                    break;

                case "savecomplex":
                    MongoDbBenchmark.SaveComplexAsync(options.Parallel, false).Wait();
                    break;

                case "savecomplexfull":
                    MongoDbBenchmark.SaveComplexAsync(options.Parallel, true).Wait();
                    break;

                default:
                    Console.WriteLine("Invalid job!");
                    break;
            }
        }
All Usage Examples Of CommandLine.Parser::ParseArguments