コード例 #1
0
        public void Valid_Custom_DataType_Option_Shoud_Be_Parsed()
        {
            CustomDataTypeConfig oConfig = new CustomDataTypeConfig();

            ConsoleCommandLineParser oParser = new ConsoleCommandLineParser();

            oParser.RegisterCustomDataTypeHandler(typeof(Color), (name, value) =>
            {
                switch (value)
                {
                case "Red":
                    return(Color.Red);

                case "Yellow":
                    return(Color.Yellow);

                case "Green":
                    return(Color.Green);

                default:
                    return(Color.None);
                }
            },

                                                  (name, value, required) =>
            {
                return(new string[] { "None", "Red", "Yellow", "Green" }.Contains(value));
            });

            oParser.ParseArguments(oConfig, @"-color ""Green""");

            Assert.AreEqual(Color.Green, oConfig.Color);
        }