//{
 //   //Note that if we declared TheEvent without the add/remove methods, the
 //   //following would still generated internally and the underlying member
 //   //(here m_theEvent) can be accessed via Reflection. The automatically
 //   //generated version has a private field with the same name as the event
 //   //(i.e. "TheEvent")
 //   add { m_theEvent += value; }
 //   remove { m_theEvent -= value; }
 //}
 //EventHandler m_theEvent; //"TheEvent" if we don't implement add/remove
 //The following shows how the event can be invoked using the underlying multicast delegate.
 //We use this knowledge when invoking via reflection (of course, normally we just write
 //if (TheEvent != null) TheEvent(this, EventArgs.Empty)
 public void ExampleInvokeTheEvent()
 {
     Delegate[] dels = TheEvent.GetInvocationList();
     foreach (Delegate del in dels)
     {
         MethodInfo method = del.Method;
         //This does the same as ThisEvent(this, EventArgs.Empty) for a single registered target
         method.Invoke(this, new object[] { EventArgs.Empty });
     }
 }
Esempio n. 2
0
 public int GetCount()
 {
     return(TheEvent?.GetInvocationList().Length ?? 0);
 }