Exemple #1
0
        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();
        }
Exemple #2
0
 public void RaiseEvent()
 {
     _event.Raise(this, EventArgs.Empty);
 }