From 2183ed757ec4eafdbc0fcdb70dae0414ef282b18 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 18 Aug 2020 13:40:15 +0200 Subject: [PATCH] Improved codegen, moved throw code to external method Also added a more detailed exception message for users --- .../ReadOnlyObservableGroupedCollection.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Microsoft.Toolkit/Collections/ReadOnlyObservableGroupedCollection.cs b/Microsoft.Toolkit/Collections/ReadOnlyObservableGroupedCollection.cs index 9ff14698..661edda8 100644 --- a/Microsoft.Toolkit/Collections/ReadOnlyObservableGroupedCollection.cs +++ b/Microsoft.Toolkit/Collections/ReadOnlyObservableGroupedCollection.cs @@ -52,8 +52,16 @@ namespace Microsoft.Toolkit.Collections // reporting the changes one by one. We consider only this case for now. if (e.OldItems?.Count > 1 || e.NewItems?.Count > 1) { - Debug.Fail("OldItems and NewItems should contain at most 1 item"); - throw new NotSupportedException(); + static void ThrowNotSupportedException() + { + throw new NotSupportedException( + "ReadOnlyObservableGroupedCollection doesn't support operations on multiple items at once.\n" + + "If this exception was thrown, it likely means support for batched item updates has been added to the " + + "underlying ObservableCollection type, and this implementation doesn't support that feature yet.\n" + + "Please consider opening an issue in https://github.com/windows-toolkit/WindowsCommunityToolkit to report this."); + } + + ThrowNotSupportedException(); } var newItem = e.NewItems?.Cast>()?.FirstOrDefault();