示例#1
0
        public void SimulateMailArrived(string from, string to, string subj, string body)
        {
            MailEventArgs args = new MailEventArgs()
            {
                Body    = body,
                From    = from,
                Subject = subj,
                To      = to
            };

            MailArrived?.Invoke(this, args);

            /*
             * EQUIVALENTE A :
             * if (MailArrived !=null)
             * {
             *  MailArrived(this, args);
             *  /*EQUIVALENTE A
             *  foreach (var item in MailArrived.GetInvocationList().ToList())
             *  {
             *      MailEventHandler mm_eh = (MailEventHandler)item;
             *      mm_eh(this, args);
             *  }
             *
             * }
             */
        }
示例#2
0
        public void SimulateMailArrived(string from, string to, string obj, string body)
        {
            MailEvevenArgs args = new MailEvevenArgs()
            {
                Body = body,
                From = from,
                To   = to,
                obj  = obj
            };

            ////primometodo
            //MailArrived?.Invoke(this, args);

            ////metodo
            //if (MailArrived != null)
            //{
            //    MailArrived(this, args);
            //}


            //metodo esplicito
            if (MailArrived != null)
            {
                foreach (var item in MailArrived.GetInvocationList().ToList())
                {
                    MailManagerEventHandler mm_eh = (MailManagerEventHandler)item;
                    mm_eh(this, args);
                }
            }
        }
示例#3
0
        public void SimulateMailArrived(string from, string to, string subject, string body)
        {
            MailEventArgs args = new MailEventArgs()
            {
                Body    = body,
                From    = from,
                Subject = subject,
                To      = to
            };

            if (MailArrived != null)
            {
                //MailArrived è null se nessuno si è sottoscritto, però poi nel foreach vado a tirarmi fuori la lista di Delegate esplicitamente
                //tramite le apposite funzioni

                foreach (Delegate item in MailArrived.GetInvocationList().ToList())
                {
                    //GetInvocationList() restituisce un'array di Delegates, che poi viene trasformato in una lista con il ToList()
                    //Questo array contiene tutti i subscribers
                    MailManagerEventHandler mm_eh = (MailManagerEventHandler)item;
                    //riesco ad invocare il metodo attraverso il suo puntatore. Castando al Delegate specifico riesco a vedere esattamente che segnatura deve avere mm_eh.
                    mm_eh(this, args); //il primo argomento è chi ha sollevato l'evento, che è proprio MailManager
                    //qui invoco di volta in volta il metodo incapsulato dentro al delegate
                }
                // Avremmo potuto scrivere solo: MailArrived(this, args);
            }
            //O avremmo potuto scrivere tutto l'if come: MailArrived?.Invoke(this,args);
        }
示例#4
0
 protected virtual void OnMailArrived(Object sender, MailArrivedEventArgs e)
 {
     if (MailArrived != null)
     {
         MailArrived.Invoke(sender, e);
     }
 }
示例#5
0
        public void SimulateMailArrived(string from, string to, string subject, string body) // simulazione di sollevamento evento
        {
            MailEventArgs args = new MailEventArgs()                                         // li ho creati nella classe delegatestuff per comodita

            {
                Body    = body,
                From    = from,
                Subject = subject,
                To      = to
            };

            // devo sollevare l'evento, quindo scorrere la lista dei delegate
            if (MailArrived != null) // se qualcuno si è sottoscritto
            {
                foreach (var item in MailArrived.GetInvocationList().ToList())
                {
                    MailManagerEventHandler mm_eh = (MailManagerEventHandler)item; // downcast per non avere un delegate generico
                    mm_eh(this, args);                                             //uso il puntatore come metodo, metto this perchè sono io che sollevo l'evento e ci passo gli argomenit
                }
            }

            // analogo di tutto quello che ho nell'if è MailArrived(this, args) o MailArrived?.Invoce(this, args)
        }
示例#6
0
        public void SimulateMailArrived(string from, string to, string subject, string body)
        {
            MailEventArgs args = new MailEventArgs()
            {
                Body    = body,
                From    = from,
                Subject = subject,
                To      = to
            };

            #region altri modi di invocare la invocation list

            /*
             * // primo metodo
             * MailArrived?.Invoke(this, args);
             *
             *
             * // secondo metodo
             * if (MailArrived != null)
             * {
             *  MailArrived(this, args);
             * }
             */
            #endregion

            // metodo esplicito
            if (MailArrived != null)
            {
                // Rise Event!!!!!!!!!!
                foreach (var item in MailArrived.GetInvocationList())
                {
                    MailManagerEventHandler mm_eh = (MailManagerEventHandler)item;
                    mm_eh(this, args);
                }
            }
        }
示例#7
0
 protected virtual void OnMailArrived(MailArrivedEventArgs args)
 {
     MailArrived?.Invoke(this, args);
 }
示例#8
0
 protected virtual void OnMailArrived(MailArrivedEventArgs e)
 {
     //Awesome.
     MailArrived?.Invoke(this, e);
 }