public static void Raise <T>(this FastSmartWeakEvent <EventHandler <T> > ev, object sender, T e) where T : EventArgs { var d = ev.GetRaiseDelegate(); if (d != null) { d(sender, e); } }
public static void Raise(this FastSmartWeakEvent <EventHandler> ev, object sender, EventArgs e) { var d = ev.GetRaiseDelegate(); if (d != null) { d(sender, e); } }
static void TypeSafetyProblem() { Console.WriteLine("TypeSafetyProblem"); Console.Write("This should cause an exception: "); try { FastSmartWeakEvent <EventHandler <EventArgs2> > fswe = new FastSmartWeakEvent <EventHandler <EventArgs2> >(); fswe.Add((sender, e) => Console.WriteLine(e.Num.ToString())); // this call is problematic because Raise isn't typesafe // FastSmartWeakEvent will do a runtime check. It's possible to remove that check to improve // performance, but that would blow a hole into the .NET type system if anyone calls Raise with // an EventArgs instance not compatible with the delegate signature. fswe.Raise(null, new EventArgs1()); Console.WriteLine("No exception -> we blew a hole into the .NET type system!"); } catch (InvalidCastException) { Console.WriteLine("Got exception as expected!"); } Console.WriteLine(); }
public static void Raise <T>(this FastSmartWeakEvent <EventHandler <T> > ev, object sender, T e) where T : EventArgs { ev.UnsafeRaise(sender, e); }
public static void Raise(this FastSmartWeakEvent <EventHandler> ev, object sender, EventArgs e) { ev.UnsafeRaise(sender, e); }
public HandlerEntry(FastSmartWeakEvent <T> parentEventSource, object targetInstance, MethodInfo targetMethod) { this.ParentEventSource = parentEventSource; this.weakReference = new WeakReference(targetInstance); this.TargetMethod = targetMethod; }