Skip to content

Commit 684a650

Browse files
committed
Improve caching of KeyChangedEventArgs
1 parent 186ff01 commit 684a650

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.ComponentModel;
6+
7+
namespace CommunityToolkit.Mvvm.Collections.Internals;
8+
9+
/// <summary>
10+
/// A helper type for the <see cref="ObservableGroup{TKey, TValue}"/> type.
11+
/// </summary>
12+
internal static class ObservableGroupHelper
13+
{
14+
/// <summary>
15+
/// The cached <see cref="PropertyChangedEventArgs"/> for <see cref="IReadOnlyObservableGroup.Key"/>
16+
/// </summary>
17+
public static readonly PropertyChangedEventArgs KeyChangedEventArgs = new(nameof(IReadOnlyObservableGroup.Key));
18+
}

CommunityToolkit.Mvvm/Collections/ObservableGroup{TKey,TValue}.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
using System.Collections.Generic;
66
using System.Collections.ObjectModel;
7-
using System.ComponentModel;
87
using System.Diagnostics;
98
using System.Linq;
9+
using CommunityToolkit.Mvvm.Collections.Internals;
1010

1111
namespace CommunityToolkit.Mvvm.Collections;
1212

@@ -20,11 +20,6 @@ namespace CommunityToolkit.Mvvm.Collections;
2020
public class ObservableGroup<TKey, TValue> : ObservableCollection<TValue>, IGrouping<TKey, TValue>, IReadOnlyObservableGroup<TKey>
2121
where TKey : notnull
2222
{
23-
/// <summary>
24-
/// The cached <see cref="PropertyChangedEventArgs"/> for <see cref="Key"/>
25-
/// </summary>
26-
private static readonly PropertyChangedEventArgs KeyChangedEventArgs = new(nameof(Key));
27-
2823
/// <summary>
2924
/// Initializes a new instance of the <see cref="ObservableGroup{TKey, TValue}"/> class.
3025
/// </summary>
@@ -69,7 +64,7 @@ public TKey Key
6964
{
7065
this.key = value;
7166

72-
OnPropertyChanged(KeyChangedEventArgs);
67+
OnPropertyChanged(ObservableGroupHelper.KeyChangedEventArgs);
7368
}
7469
}
7570
}

0 commit comments

Comments
 (0)