Repository navigation
Expand file tree
/
Copy pathChangeSet.cs
More file actions
64 lines (53 loc) · 2.09 KB
/
Copy pathChangeSet.cs
File metadata and controls
64 lines (53 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) 2011-2023 Roland Pheasant. All rights reserved.
// Roland Pheasant licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
// ReSharper disable once CheckNamespace
namespace DynamicData;
/// <summary>
/// A collection of changes.
/// </summary>
/// <typeparam name="TObject">The type of the object.</typeparam>
/// <typeparam name="TKey">The type of the key.</typeparam>
public class ChangeSet<TObject, TKey> : List<Change<TObject, TKey>>, IChangeSet<TObject, TKey>
where TObject : notnull
where TKey : notnull
{
/// <summary>
/// An empty change set.
/// </summary>
public static readonly ChangeSet<TObject, TKey> Empty = [];
/// <summary>
/// Initializes a new instance of the <see cref="ChangeSet{TObject, TKey}"/> class.
/// </summary>
public ChangeSet()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ChangeSet{TObject, TKey}"/> class.
/// </summary>
/// <param name="collection">The collection of items to start the change set with.</param>
public ChangeSet(IEnumerable<Change<TObject, TKey>> collection)
: base(collection)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ChangeSet{TObject, TKey}"/> class.
/// </summary>
/// <param name="capacity">The initial capacity of the change set.</param>
public ChangeSet(int capacity)
: base(capacity)
{
}
/// <inheritdoc />
public int Adds => this.Count(c => c.Reason == ChangeReason.Add);
/// <inheritdoc />
public int Moves => this.Count(c => c.Reason == ChangeReason.Moved);
/// <inheritdoc />
public int Refreshes => this.Count(c => c.Reason == ChangeReason.Refresh);
/// <inheritdoc />
public int Removes => this.Count(c => c.Reason == ChangeReason.Remove);
/// <inheritdoc />
public int Updates => this.Count(c => c.Reason == ChangeReason.Update);
/// <inheritdoc />
public override string ToString() => $"ChangeSet<{typeof(TObject).Name}.{typeof(TKey).Name}>. Count={Count}";
}