Ejemplo n.º 1
0
        public void Custom_types_and_conversion_logic_can_be_specified()
        {
            var argument = new Argument <MyCustomType>((SymbolResult parsed, out MyCustomType value) =>
            {
                var custom = new MyCustomType();
                foreach (var a in parsed.Arguments)
                {
                    custom.Add(a);
                }

                value = custom;
                return(true);
            })
            {
                Arity = ArgumentArity.ZeroOrMore,
                Name  = "arg"
            };

            var parser = new Parser(
                new Command("custom", "",
                            argument: argument));

            var result = parser.Parse("custom one two three");

            var customType = result.CommandResult
                             .GetArgumentValueOrDefault <MyCustomType>("arg");

            customType
            .Values
            .Should()
            .BeEquivalentTo("one", "two", "three");
        }
Ejemplo n.º 2
0
        public void Custom_types_and_conversion_logic_can_be_specified()
        {
            var argument = new Argument <MyCustomType>(parsed =>
            {
                var custom = new MyCustomType();
                foreach (var a in parsed.Arguments)
                {
                    custom.Add(a);
                }

                return(ArgumentResult.Success(custom));
            })
            {
                Arity = ArgumentArity.ZeroOrMore
            };

            var parser = new Parser(
                new Command("custom", "",
                            argument: argument));

            var result = parser.Parse("custom one two three");

            var customType = result.CommandResult.GetValueOrDefault <MyCustomType>();

            customType
            .Values
            .Should()
            .BeEquivalentTo("one", "two", "three");
        }