2 using EventDictionary = System.Collections.Generic.Dictionary<(System.IntPtr desc, object evtDelegate), (System.IntPtr evtCallerPtr, Efl.EventCb evtCaller)>;
10 /// <summary>Observe the ownership state of an Eo wrapper and control its life-cycle.</summary>
11 public class WrapperSupervisor
13 private System.WeakReference weakRef;
14 #pragma warning disable CS0414
15 private Efl.Eo.IWrapper sharedRef;
16 #pragma warning restore CS0414
17 private EventDictionary eoEvents;
19 /// <summary>Create a new supervisor for the given.</summary>
20 /// <param name="obj">Efl object to be supervised.</param>
21 public WrapperSupervisor(Efl.Eo.IWrapper obj)
23 weakRef = new WeakReference(obj);
25 eoEvents = new EventDictionary();
28 /// <summary>Efl object being supervised.</summary>
29 public Efl.Eo.IWrapper Target
33 return (Efl.Eo.IWrapper) weakRef.Target;
37 /// <summary>Dictionary that holds the events related with the supervised object.</summary>
38 public EventDictionary EoEvents
46 /// <summary>To be called when the object is uniquely owned by C#, removing its strong reference and making it available to garbage collection.</summary>
47 public void MakeUnique()
52 /// <summary>To be called when the object is owned in the native library too, adding a strong reference to it and making it unavailable for garbage collection.</summary>
53 public void MakeShared()
55 if (this.Target == null)
56 throw new InvalidOperationException("Tried to make a null reference shared.");
57 sharedRef = this.Target;