Beispiel #1
0
        private Key SetOption(Option option, OperationResult result)
        {
            Key currentKey = null;
            var keyOpt = option as Key;
            var flagOpt = option as Flag;

            if (keyOpt != null)
            {
                currentKey = keyOpt;
            }
            else if (flagOpt != null)
            {
                result.Flags[flagOpt.Long] = true;
            }
            else
            {
                throw new InvalidOperationException($"The option \"{option.ToString()}\" is of an unknown type (\"{option.GetType().Name}\")");
            }
            return currentKey;
        }
Beispiel #2
0
        private OperationResult BuildDefaultResult(string operationName)
        {
            var result = new OperationResult(operationName, restArgumentDefaultValue);

            foreach (var option in options)
            {
                var keyOpt = option as Key;
                var flagOpt = option as Flag;
                if (keyOpt != null)
                {
                    result.Keys[keyOpt.Long] = keyOpt.DefaultValue;
                }
                else if (flagOpt != null)
                {
                    result.Flags[flagOpt.Long] = false;
                }
                else
                {
                    throw new InvalidOperationException($"The option \"{option.ToString()}\" is of an unknown type (\"{option.GetType().Name}\")");
                }
            }
            foreach (var argument in arguments)
            {
                result.Arguments[argument.Name] = argument.DefaultValue;
            }
            return result;
        }