You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.2 KiB
86 lines
2.2 KiB
5 years ago
|
// Needed for NET40
|
||
|
#if !NET_4_6
|
||
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
|
||
|
namespace LinqInternal.Collections.Specialized
|
||
|
{
|
||
|
[Serializable]
|
||
|
internal sealed class ValueCollection<TKey, TValue> : ICollection<TValue>, ICollection, IReadOnlyCollection<TValue>
|
||
|
{
|
||
|
private readonly IDictionary<TKey, TValue> _wrapped;
|
||
|
|
||
|
internal ValueCollection(IDictionary<TKey, TValue> wrapped)
|
||
|
{
|
||
|
if (wrapped == null)
|
||
|
{
|
||
|
throw new ArgumentNullException("wrapped");
|
||
|
}
|
||
|
_wrapped = wrapped;
|
||
|
}
|
||
|
|
||
|
public int Count
|
||
|
{
|
||
|
get { return _wrapped.Count; }
|
||
|
}
|
||
|
|
||
|
bool ICollection.IsSynchronized
|
||
|
{
|
||
|
get { return ((ICollection)_wrapped).IsSynchronized; }
|
||
|
}
|
||
|
|
||
|
object ICollection.SyncRoot
|
||
|
{
|
||
|
get { return ((ICollection)_wrapped).SyncRoot; }
|
||
|
}
|
||
|
|
||
|
bool ICollection<TValue>.IsReadOnly
|
||
|
{
|
||
|
get { return true; }
|
||
|
}
|
||
|
|
||
|
public void CopyTo(TValue[] array, int arrayIndex)
|
||
|
{
|
||
|
Extensions.CanCopyTo(_wrapped.Count, array, arrayIndex);
|
||
|
_wrapped.ConvertProgressive(pair => pair.Value).CopyTo(array, arrayIndex);
|
||
|
}
|
||
|
|
||
|
public IEnumerator<TValue> GetEnumerator()
|
||
|
{
|
||
|
return _wrapped.ConvertProgressive(pair => pair.Value).GetEnumerator();
|
||
|
}
|
||
|
|
||
|
void ICollection.CopyTo(Array array, int index)
|
||
|
{
|
||
|
((ICollection)_wrapped).CopyTo(array, index);
|
||
|
}
|
||
|
|
||
|
void ICollection<TValue>.Add(TValue item)
|
||
|
{
|
||
|
throw new NotSupportedException();
|
||
|
}
|
||
|
|
||
|
void ICollection<TValue>.Clear()
|
||
|
{
|
||
|
throw new NotSupportedException();
|
||
|
}
|
||
|
|
||
|
bool ICollection<TValue>.Contains(TValue item)
|
||
|
{
|
||
|
return _wrapped.Where(pair => EqualityComparer<TValue>.Default.Equals(item, pair.Value)).HasAtLeast(1);
|
||
|
}
|
||
|
|
||
|
bool ICollection<TValue>.Remove(TValue item)
|
||
|
{
|
||
|
throw new NotSupportedException();
|
||
|
}
|
||
|
|
||
|
IEnumerator IEnumerable.GetEnumerator()
|
||
|
{
|
||
|
return GetEnumerator();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
#endif
|