Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            args = new string[]
            {
                @"/key",
                @"/s",
                @"StringValue",
                @"/i",
                @"1488",
                @"/d",
                @"14,88"
            };

            CmdLineParser parser = new CmdLineParser();
            try
            {
                Console.WriteLine("Params:");
                Console.WriteLine("Params usage:\n\b{0}", parser.GetUsageText<TestOptionClass>());
                Console.WriteLine();

                parser.ParseCmdLine(args);
                TestOptionClass options = parser.GetCmdLineOptions<TestOptionClass>();
                Console.WriteLine("Test Class Object:");
                Console.WriteLine("Required Key param: {0}", options.KeyParam);
                Console.WriteLine("Not Required Key param: {0}", options.NotRequiredKeyParam);
                Console.WriteLine("Required String param: {0}", options.StringParam);
                Console.WriteLine("Required Int param: {0}", options.IntParam);
                Console.WriteLine("Not Required Double param: {0}", options.DoubleParam);
            }
            catch(ParseCmdLineException parseEx)
            {
                switch(parseEx.ParseError)
                {
                    case EParseError.E_KEYEXISTS:
                        break;
                    case EParseError.E_KEYNOTFOUND:
                        break;
                }
                Console.WriteLine("Parse cmd line exception!");
            }
            catch(OptionParserException optionEx)
            {
                switch(optionEx.ErrorCode)
                {
                    case EOptionParserError.E_INVALID_CONVERT_TYPE:
                        break;
                    case EOptionParserError.E_INVALID_KEY_PROPERTY_TYPE:
                        break;
                    case EOptionParserError.E_REQUIRED_OPTION_NOT_EXIST:
                        break;
                }
                Console.WriteLine("Option class creation exception!");
            }
        }