Skip to content

Commit b601e57

Browse files
committed
code styling and perf improvement
1 parent fe1f18a commit b601e57

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Microsoft.Toolkit/Collections/ObservableGroup.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ namespace Microsoft.Toolkit.Collections
1919
[DebuggerDisplay("Key = {Key}, Count = {Count}")]
2020
public class ObservableGroup<TKey, TValue> : ObservableCollection<TValue>, IGrouping<TKey, TValue>, IReadOnlyObservableGroup
2121
{
22-
private TKey key;
22+
/// <summary>
23+
/// The cached <see cref="PropertyChangedEventArgs"/> for <see cref="Key"/>
24+
/// </summary>
25+
private static readonly PropertyChangedEventArgs KeyChangedEventArgs = new PropertyChangedEventArgs(nameof(Key));
2326

2427
/// <summary>
2528
/// Initializes a new instance of the <see cref="ObservableGroup{TKey, TValue}"/> class.
@@ -51,6 +54,8 @@ public ObservableGroup(TKey key, IEnumerable<TValue> collection)
5154
Key = key;
5255
}
5356

57+
private TKey key;
58+
5459
/// <summary>
5560
/// Gets or sets the key of the group.
5661
/// </summary>
@@ -62,8 +67,8 @@ public TKey Key
6267
if (!EqualityComparer<TKey>.Default.Equals(this.key, value))
6368
{
6469
this.key = value;
65-
66-
OnPropertyChanged(new PropertyChangedEventArgs(nameof(Key)));
70+
71+
OnPropertyChanged(KeyChangedEventArgs);
6772
}
6873
}
6974
}

0 commit comments

Comments
 (0)