コード例 #1
0
 /// <summary>
 /// Constructs a new instance of <see cref="Cache{TKey,TValue}"/> using an explicit <see cref="IEqualityComparer{TKey}"/> of TKey to comparer keys.
 /// </summary>
 /// <param name="keyComparer">The <see cref="IEqualityComparer{TKey}"/> of TKey to compare keys with.</param>
 public Cache(IEqualityComparer <TKey> keyComparer)
 {
     _keyComparer = keyComparer;
     _Level1Cache = new Level1CacheClass <TKey>(keyComparer);
     _Level2Cache = new WeakDictionary <object, bool, object>(new ObjectComparerClass <TKey> {
         _KeyComparer = keyComparer
     }, EqualityComparer <bool> .Default);
 }
コード例 #2
0
        Cache(SerializationInfo serializationInfo, StreamingContext streamingContext)
        {
            _keyComparer = (IEqualityComparer <TKey>)serializationInfo.GetValue("Comparer", typeof(IEqualityComparer <TKey>));
            _Level1Cache = new Level1CacheClass <TKey>(_keyComparer);
            _Level2Cache = new WeakDictionary <object, bool, object>(new ObjectComparerClass <TKey> {
                _KeyComparer = _keyComparer
            }, EqualityComparer <bool> .Default);

            foreach (var kvp in (IEnumerable <KeyValuePair <TKey, TValue> >)serializationInfo.GetValue("Items", typeof(List <KeyValuePair <TKey, TValue> >)))
            {
                this.GetOldest(kvp.Key, kvp.Value);
            }
        }