forked from izrik/FbxSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjectView.cs
49 lines (41 loc) · 1.2 KB
/
ObjectView.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
using System;
using System.Linq;
using System.Collections.Generic;
namespace FbxSharp
{
public class ObjectView<T> : ObjectView<T, FbxObject>
where T : FbxObject
{
public ObjectView(IList<FbxObject> collection, Action<EventHandler> collectionChanged)
: base(collection, collectionChanged)
{
}
}
public class ObjectView<T, U>
where T : U
{
public ObjectView(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;
T value = default(T);
void CollectionChanged(object sender, EventArgs e)
{
value = default(T);
collectionHasChanged = true;
}
public T Get()
{
if (collectionHasChanged)
{
value = (T)collection.FirstOrDefault(x => x is T);
collectionHasChanged = false;
}
return value;
}
}
}