Пример #1
0
        /// <summary>
        /// Evaluate a predicate Expression and determine whether a key range can
        /// be found that completely satisfies the expression. If this method returns
        /// true then the key range returned by <see cref="GetKeyRange"/> will return
        /// only records which match the expression.
        /// </summary>
        /// <param name="expression">The expression to evaluate.</param>
        /// <returns>
        /// True if the key range returned by <see cref="GetKeyRange"/> will perfectly
        /// match all records found by the expression.
        /// </returns>
        public static bool KeyRangeIsExact(Expression <Predicate <KeyValuePair <TKey, TValue> > > expression)
        {
            if (null == expression)
            {
                throw new ArgumentNullException("expression");
            }

            return(KeyExpressionEvaluator <TKey> .KeyRangeIsExact(expression.Body, KeyMemberInfo));
        }
        /// <summary>
        /// Optimize a where statement which uses this collection.
        /// </summary>
        /// <param name="expression">
        /// The predicate determining which items should be enumerated.
        /// </param>
        /// <returns>
        /// An enumerator matching only the records matched by the predicate.
        /// </returns>
        public PersistentDictionaryLinqKeyEnumerable <TKey, TValue> Where(Expression <Predicate <TKey> > expression)
        {
            if (null == expression)
            {
                throw new ArgumentNullException("expression");
            }

            Predicate <TKey> predicate = KeyExpressionEvaluator <TKey> .KeyRangeIsExact(expression) ? x => true : expression.Compile();

            return(new PersistentDictionaryLinqKeyEnumerable <TKey, TValue>(
                       this.Dictionary,
                       expression,
                       predicate,
                       false));
        }