Exemplo n.º 1
0
 public static void RegisterInterest(this object target, object interestedParty)
 {
     Broadcaster.Cleanup();
     Broadcaster.InterestList.Add(new Broadcaster.Pair
     {
         target   = new WeakReference(target),
         interest = new WeakReference(interestedParty)
     });
 }
Exemplo n.º 2
0
 public static void Broadcast(this object obj, string message)
 {
     Broadcaster.Cleanup();
     foreach (WeakReference weakReference in (from p in Broadcaster.InterestList
                                              where p.target.Target == obj
                                              select p.interest into r
                                              where r.IsAlive
                                              select r).ToList <WeakReference>())
     {
         MethodInfo method = weakReference.Target.GetType().GetMethod(message, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
         if (method.GetParameters().Length == 1)
         {
             method.Invoke(weakReference.Target, new object[]
             {
                 obj
             });
         }
         else
         {
             method.Invoke(weakReference.Target, null);
         }
     }
 }
Exemplo n.º 3
0
 public static void UnregisterInterest(this object target, object interestedParty)
 {
     Broadcaster.Cleanup();
     Broadcaster.InterestList.Remove(Broadcaster.InterestList.FirstOrDefault((Broadcaster.Pair p) => p.target.Target == target && p.interest.Target == interestedParty));
 }