forked from StephaneDelcroix/MobileInception.Interactivity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAttachableCollection.cs
46 lines (39 loc) · 937 Bytes
/
AttachableCollection.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
//
// AttachableCollection.cs
//
// Author:
// Stephane Delcroix <[email protected]>
//
// Copyright (c) 2013 Mobile Inception
//
using System;
using MonoTouch.Foundation;
using System.Collections.Generic;
namespace MobileInception.Interactivity
{
public abstract class AttachableCollection<T> : List<T>, IAttachedObject where T : IAttachedObject
{
public void Attach (NSObject target)
{
AssociatedObject = target;
OnAttached ();
}
public void Detach ()
{
OnDetaching ();
AssociatedObject = null;
}
public NSObject AssociatedObject {
get {
NSObject @object;
if (AssociatedObjectWeak.TryGetTarget (out @object))
return @object;
return null;
}
private set { AssociatedObjectWeak = new WeakReference<NSObject> (value); }
}
WeakReference<NSObject> AssociatedObjectWeak { get; set; }
protected abstract void OnAttached ();
protected abstract void OnDetaching ();
}
}