示例#1
0
        public TryResult WithKey(string key, Action <Argument> argumentAction)
        {
            if (!keys.ContainsKey(key))
            {
                return(TryResult.Fail());
            }
            var argument = keys[key];

            argumentAction(argument);
            return(TryResult.Pass());
        }
示例#2
0
        public TryResult At(int position, Action <Argument> argumentAction)
        {
            if (position < 0 || position >= arguments.Count)
            {
                return(TryResult.Fail());
            }
            var argument = arguments[position];

            argumentAction(argument);
            return(TryResult.Pass());
        }
示例#3
0
        public TryResult At(int position, string command, Action argumentAction)
        {
            if (position < 0 || position >= arguments.Count)
            {
                return(TryResult.Fail());
            }
            var argument = arguments[position];

            if (argument.Value != command)
            {
                return(TryResult.Fail());
            }
            argumentAction();
            return(TryResult.Pass());
        }
示例#4
0
        public TryResult WithTypedKeyOptional <T>(string key, Action <Argument> argumentAction) where T : IConvertible
        {
            if (!keys.ContainsKey(key))
            {
                return(TryResult.Pass());
            }

            try
            {
                Convert.ChangeType(keys[key].Value, typeof(T));
            }
            catch (InvalidCastException)
            {
                return(TryResult.Fail());
            }

            var argument = keys[key];

            argumentAction(argument);
            return(TryResult.Pass());
        }