示例#1
0
 public void TestSimpleIntPresent()
 {
     Args.Args args = new Args.Args("x#", new string[] { "-x", "42" });
     Assert.AreEqual(1, args.Cardinality());
     Assert.IsTrue(args.Has("x"));
     Assert.AreEqual(42, args.GetInt("x"));
 }
示例#2
0
        public void TestSingleStringArrayWithMultipleArgsPresent()
        {
            Args.Args args = new Args.Args("x[*],l,d#", new String[] { "-x", "param1", "param2", "param3", "-l", "-d", "10" });
            Assert.AreEqual(3, args.Cardinality());
            Assert.IsTrue(args.Has("x"));
            Assert.IsTrue(args.Has("l"));
            Assert.IsTrue(args.Has("d"));

            String[] expected = new String[] { "param1", "param2", "param3" };
            String[] actual   = args.GetStringArray("x");
            for (int i = 0; i < 3; i++)
            {
                Assert.AreEqual(expected[i], actual[i]);
            }
            Assert.IsTrue(args.GetBoolean("l"));
            Assert.AreEqual(10, args.GetInt("d"));
        }
示例#3
0
        static void Main(string[] args)
        {
            string schema = "bool,int#,double##,string*,stringArray[*]";

            string[]  vargs  = { "-bool", "-int", "10", "-double", System.Math.PI.ToString(), "-string", "hi", "-stringArray", "Hello", "World" };
            Args.Args parser = new Args.Args(schema, vargs);

            Console.WriteLine("bool: {0}", parser.GetBoolean("bool"));
            Console.WriteLine("int: {0}", parser.GetInt("int"));
            Console.WriteLine("double: {0}", parser.GetDouble("double"));
            Console.WriteLine("string: {0}", parser.GetString("string"));

            string[] stringArray = parser.GetStringArray("stringArray");
            for (int i = 0; i < stringArray.Length; i++)
            {
                Console.WriteLine("stringArray {0}: {1}", i, stringArray[i]);
            }

            Console.ReadLine();
        }