/
AGSListChangedEventArgs.cs
72 lines (64 loc) · 2.11 KB
/
AGSListChangedEventArgs.cs
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
65
66
67
68
69
70
71
using System.Collections.Generic;
namespace AGS.API
{
/// <summary>
/// How did the list change?
/// </summary>
public enum ListChangeType
{
/// <summary>
/// An item was added to the list.
/// </summary>
Add,
/// <summary>
/// An item was removed from the list.
/// </summary>
Remove,
}
/// <summary>
/// Event arguments for a list change.
/// </summary>
public class AGSListChangedEventArgs<TItem>
{
private IEnumerable<AGSListItem<TItem>> _items;
private AGSListItem<TItem> _singleItem;
/// <summary>
/// Initializes a new instance of the <see cref="T:AGS.API.AGSListChangedEventArgs`1"/> class.
/// </summary>
/// <param name="changeType">Change type.</param>
/// <param name="item">Item.</param>
public AGSListChangedEventArgs(ListChangeType changeType, AGSListItem<TItem> item)
{
ChangeType = changeType;
_singleItem = item;
}
/// <summary>
/// Initializes a new instance of the <see cref="T:AGS.API.AGSListChangedEventArgs`1"/> class.
/// </summary>
/// <param name="changeType">Change type.</param>
/// <param name="items">Items.</param>
public AGSListChangedEventArgs(ListChangeType changeType, IEnumerable<AGSListItem<TItem>> items)
{
ChangeType = changeType;
_items = items;
}
/// <summary>
/// How was the list changed?
/// </summary>
/// <value>The type of the change.</value>
public ListChangeType ChangeType { get; private set; }
/// <summary>
/// Gets the items which were involved in the change (either added or removed depending on <see cref="ChangeType"/>).
/// </summary>
/// <value>The item.</value>
public IEnumerable<AGSListItem<TItem>> Items
{
get
{
if (_items != null) return _items;
return getSingleItem();
}
}
private IEnumerable<AGSListItem<TItem>> getSingleItem() { yield return _singleItem; }
}
}