#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 create( ImmutableDictionary source) where TKey : notnull => new(source); } public class ImmutableDictionaryValueCollection : ICollection where TKey : notnull { readonly IImmutableDictionary _source; public ImmutableDictionaryValueCollection(IImmutableDictionary 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 GetEnumerator() => _source.Values.GetEnumerator(); public bool Remove(TValue item) => throw new NotSupportedException(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } }