From 8ca354e5d7bd0dd830c7f91ae700df84792bca21 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Sat, 1 Nov 2025 16:42:56 -0400 Subject: [PATCH] chore: Support mutations in AggregateDictionary (optionally) --- .../Collections/AggregateDictionary.cs | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/client/spark_core/Collections/AggregateDictionary.cs b/src/client/spark_core/Collections/AggregateDictionary.cs index dd74907ef..8d6e5863a 100644 --- a/src/client/spark_core/Collections/AggregateDictionary.cs +++ b/src/client/spark_core/Collections/AggregateDictionary.cs @@ -7,22 +7,29 @@ namespace Spark.Core.Collections { public static class AggregateDictionary { public static AggregateDictionary Create( - IDictionary src1, IDictionary src2) where K : notnull => - new(src1, src2); + IDictionary src1, IDictionary src2, bool isReadOnly = true) where K : notnull => + new(src1, src2, isReadOnly); } public class AggregateDictionary : IDictionary where TKey : notnull { readonly IDictionary src1; readonly IDictionary src2; + readonly bool isReadOnly; public AggregateDictionary(IDictionary src1, IDictionary src2) { this.src1 = src1; this.src2 = src2; } + public AggregateDictionary(IDictionary src1, IDictionary src2, bool isReadOnly = true) { + this.src1 = src1; + this.src2 = src2; + this.isReadOnly = isReadOnly; + } + public int Count => src1.Count + src2.Count; - public bool IsReadOnly => true; + public bool IsReadOnly => isReadOnly; public ICollection Keys => AggregateCollection.Create(src1.Keys, src2.Keys); @@ -40,7 +47,12 @@ namespace Spark.Core.Collections { } throw new KeyNotFoundException(); } - set => throw new NotSupportedException(); + set { + if (isReadOnly) { + throw new NotSupportedException(); + } + src1[key] = value; + } } public void Add(TKey key, TValue value) =>