From 5398f7aa46546da6408b38b8cc9233b4e967f7fb Mon Sep 17 00:00:00 2001 From: lindexi Date: Thu, 31 Oct 2024 17:06:52 +0800 Subject: [PATCH] Fix InlineDictionary Behavior for Single Item Reassignment (#17370) * Fix InlineDictionary Behavior for Single Item Reassignment Previous Behavior: - When the `Set` method was called, it ignored the `overwrite` parameter if the dictionary contained only one item. - This caused the `Set` method to behave like the `Add` method, leading to unexpected behavior in composition animations. - Specifically, the second composition animation would not play because it could not replace the first animation. Instead, it was added after the first animation, preventing it from being executed. Updated Behavior: - The `InlineDictionary` now respects the `overwrite` parameter even when it contains only one item. - This ensures that the second composition animation can overwrite the first one, allowing it to play correctly. * Append unit test for InlineDictionary * keep the `(TKey)_data` in a variable and reuse it below line 90 so we avoid a double cast * Rename the test method * Remove the unnecessary assignment code. --- src/Avalonia.Base/Utilities/SmallDictionary.cs | 12 ++++++++++-- .../Utilities/InlineDictionaryTests.cs | 11 +++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Base/Utilities/SmallDictionary.cs b/src/Avalonia.Base/Utilities/SmallDictionary.cs index ea6769c1ba..fbb22058a6 100644 --- a/src/Avalonia.Base/Utilities/SmallDictionary.cs +++ b/src/Avalonia.Base/Utilities/SmallDictionary.cs @@ -77,9 +77,17 @@ internal struct InlineDictionary : IEnumerable(); + dic["foo"] = 1; + Assert.Equal(1, dic["foo"]); + + dic["foo"] = 2; + Assert.Equal(2, dic["foo"]); + } + [Fact] public void Enumeration_After_Add_With_Internal_Array_Works() {