This is in anticipation of decoupling BlueOrb from Spark. * Bts.Collections * Bts.Core * Bts.Disposables * Bts.Numerics
49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
#nullable enable
|
|
namespace Spark.Core.Collections {
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Immutable;
|
|
using System.Linq;
|
|
|
|
public static class ImmutableDictionaryValueCollection {
|
|
public static ImmutableDictionaryValueCollection<TKey, TValue> create<TKey, TValue>(
|
|
ImmutableDictionary<TKey, TValue> source) where TKey : notnull => new(source);
|
|
}
|
|
|
|
public class ImmutableDictionaryValueCollection<TKey, TValue> : ICollection<TValue> where TKey : notnull {
|
|
readonly IImmutableDictionary<TKey, TValue> _source;
|
|
|
|
public ImmutableDictionaryValueCollection(IImmutableDictionary<TKey, TValue> source) =>
|
|
_source = source;
|
|
|
|
public int Count => _source.Count;
|
|
|
|
public bool IsReadOnly => true;
|
|
|
|
public void Add(TValue item) =>
|
|
throw new NotSupportedException();
|
|
|
|
public void Clear() =>
|
|
throw new NotSupportedException();
|
|
|
|
public bool Contains(TValue item) =>
|
|
_source.Values.Contains(item);
|
|
|
|
public void CopyTo(TValue[] array, int array_index) {
|
|
foreach (var k in _source.Values) {
|
|
array[array_index++] = k;
|
|
}
|
|
}
|
|
|
|
public IEnumerator<TValue> GetEnumerator() =>
|
|
_source.Values.GetEnumerator();
|
|
|
|
public bool Remove(TValue item) =>
|
|
throw new NotSupportedException();
|
|
|
|
IEnumerator IEnumerable.GetEnumerator() =>
|
|
GetEnumerator();
|
|
}
|
|
}
|