Пример #1
0
        /// <summary>
        /// Adds the placed token.
        /// </summary>
        /// <param name="position">The position.</param>
        /// <param name="token">The token.</param>
        protected void AddPlaced(int position, TokenItem token)
        {
            if (token == null)
            {
                throw new ArgumentNullException("token");
            }
            if (position < 0)
            {
                throw new ArgumentOutOfRangeException("position", position, "Position must be greater than or equal to zero");
            }
            else if (position == int.MaxValue)
            {
                throw new InvalidOperationException("Can't set rest arguments via AddPlaces");
            }

            while (_placedItems.Count < position + 1)
            {
                _placedItems.Add(null);
            }

            if (_placedItems[position] != null)
            {
                throw new ArgumentException("Can't place two members at the same position");
            }

            _placedItems[position] = token;
        }
Пример #2
0
        /// <summary>
        /// Tries to get a token by its name.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="caseSensitive">if set to <c>true</c> [case sensitive].</param>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        public virtual bool TryGetToken(string name, bool caseSensitive, out TokenItem token)
        {
            if (_csNames.Count == 0)
            {
                foreach (TokenMember tm in _tokens.Values)
                {
                    foreach (TokenItem tk in tm.Tokens)
                    {
                        if (tk.Aliases != null)
                        {
                            foreach (string alias in tk.Aliases)
                            {
                                _csNames.Add(alias, tk);
                            }
                        }
                    }
                }
            }
            if (!caseSensitive)
            {
                if (_ciNames.Count != _csNames.Count)
                {
                    _ciNames.Clear();

                    foreach (KeyValuePair <string, TokenItem> tk in _csNames)
                    {
                        _ciNames.Add(tk.Key, tk.Value);
                    }
                }
            }

            return((caseSensitive ? _csNames : _ciNames).TryGetValue(name, out token));
        }
Пример #3
0
        /// <summary>
        /// Sets the rest token.
        /// </summary>
        /// <param name="token">The token.</param>
        protected void SetRest(TokenItem token)
        {
            if (token == null)
            {
                throw new ArgumentNullException("token");
            }

            if (_rest != null)
            {
                throw new InvalidOperationException("Can only set one rest argument");
            }

            _rest = token;
        }