forked from izrik/FbxSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollectionView.cs
More file actions
97 lines (77 loc) · 2.2 KB
/
CollectionView.cs
File metadata and controls
97 lines (77 loc) · 2.2 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Collections.Generic;
using System.Linq;
namespace FbxSharp
{
public class CollectionView<T> : CollectionView<T, FbxObject>
where T : FbxObject
{
public CollectionView(IList<FbxObject> collection, Action<EventHandler> collectionChanged)
: base(collection, collectionChanged)
{
}
}
public class CollectionView<T, U> : IEnumerable<T>
where T : U
{
public CollectionView(IList<U> collection, Action<EventHandler> collectionChanged)
{
if (collection == null) throw new ArgumentNullException("collection");
this.collection = collection;
collectionChanged(this.CollectionChanged);
}
readonly IList<U> collection;
bool collectionHasChanged = true;
readonly List<T> _list = new List<T>();
void CollectionChanged(object sender, EventArgs e)
{
_list.Clear();
collectionHasChanged = true;
}
List<T> List
{
get
{
if (collectionHasChanged)
{
_list.Clear();
_list.AddRange(collection.Where(x => x is T).Cast<T>());
collectionHasChanged = false;
}
return _list;
}
}
public int IndexOf(T item)
{
return List.IndexOf(item);
}
public T this[int index]
{
get { return List[index]; }
}
public bool Contains(T item)
{
return List.Contains(item);
}
public void CopyTo(T[] array, int arrayIndex)
{
List.CopyTo(array, arrayIndex);
}
public int Count
{
get { return List.Count; }
}
#region IEnumerable implementation
public IEnumerator<T> GetEnumerator()
{
return List.GetEnumerator();
}
#endregion
#region IEnumerable implementation
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
#endregion
}
}