This repository was archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathObservableCollectionEx.cs
More file actions
51 lines (47 loc) · 1.83 KB
/
Copy pathObservableCollectionEx.cs
File metadata and controls
51 lines (47 loc) · 1.83 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
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace GitHub.Extensions
{
/// <summary>
/// A non-braindead way to expose a read-only view on an <see cref="ObservableCollection{T}"/>.
/// </summary>
/// <typeparam name="T">The type of elements in the collection.</typeparam>
/// <remarks>
/// <see cref="ReadOnlyObservableCollection{T}"/> fails in its only purpose by Not. Freaking.
/// Exposing. INotifyCollectionChanged. We define our own <see cref="IReadOnlyObservableCollection{T}"/>
/// type and use this class to expose it. Seriously.
/// </remarks>
public class ObservableCollectionEx<T> : ObservableCollection<T>, IReadOnlyObservableCollection<T>
{
/// <summary>
/// Initializes a new instance of the <see cref="ObservableCollectionEx{T}"/> class.
/// </summary>
public ObservableCollectionEx()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ObservableCollectionEx{T}"/> class that
/// contains elements copied from the specified list.
/// </summary>
public ObservableCollectionEx(List<T> list)
: base(list)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ObservableCollectionEx{T}"/> class that
/// contains elements copied from the specified collection.
/// </summary>
public ObservableCollectionEx(IEnumerable<T> collection)
: base(collection)
{
}
/// <summary>
/// Adds the elements of the specified collection to the end of the list.
/// </summary>
/// <param name="items">The items to add.</param>
public void AddRange(IEnumerable<T> items)
{
foreach (var item in items) Add(item);
}
}
}