Experimental By Example


This page contains experimental functions which are not included in Downloads but exist in the head revision of the source code

#1 The Default API allows you to assign a default value for an argument if the argument has not been provided

        [Test]
        public void DefaultShouldWork()
        {
            var ethalon = TimeSpan.FromSeconds(10);

            var map = new ArgumentsMap().AddKnownArgument("timeout")
                .Default(ethalon);

            var result = new ArgumentParser(map).Parse(null);

            Assert.IsTrue(result.IsValid);
            Assert.AreEqual(ethalon, result.GetValue<TimeSpan>("timeout"));
        }


#2 The IgnoreUnknownArguments API allows you to make a parser to ignore unmapped arguments

        [Test]
        public void IgnoreUnknownArgumentsWorks()
        {
            var args = new List<string>
            {
                  "--waste",
                  "injection",
                  "--declared",
                  "true"
            };

            var map = new ArgumentsMap().IgnoreUnkonwnArguments(true)
                .AddKnownArgument("Declared")
                .Type<bool>();

            var result = new ArgumentParser(map).ParseAsDynamicResult(args);

            Assert.IsNull(result.Waste);
            Assert.IsTrue(result.Declared);
            
        }

Last edited Apr 28, 2011 at 8:12 PM by ljuk, version 2

Comments

No comments yet.