Example #1
0
        public void PerformForDialog()
        {
            ReportFeedback rfb = new ReportFeedback(ReportOnDialog);
            DoubleIt       bo  = new DoubleIt();

            bo.DoIt(100, rfb);
        }
Example #2
0
        public void PerformForConsole()
        {
            ReportFeedback rfb = new ReportFeedback(ReportOnConsole);
            DoubleIt       bo  = new DoubleIt();

            bo.DoIt(10, rfb);
        }
Example #3
0
        public void PerformUsingSyntacticSugar()
        {
            DoubleIt bo = new DoubleIt();

            bo.DoIt(6, ReportOnDialog); //No needs to construct a delegate object.

            //No need to define a callback method, use lambda expression instead.
            bo.DoIt(8, (val) => Console.WriteLine(val));
        }
Example #4
0
        public void FancyPerformForAll()
        {
            ReportFeedback rfb1 = new ReportFeedback(ReportOnConsole);
            ReportFeedback rfb2 = new ReportFeedback(ReportOnDialog);

            ReportFeedback rfbChain = null;

            rfbChain += rfb1;
            rfbChain += rfb2;

            DoubleIt bo = new DoubleIt();

            bo.DoIt(100, rfbChain);
        }
Example #5
0
        public void PerformForAllUsingInvocationList()
        {
            ReportFeedback rfb1 = new ReportFeedback(ReportOnConsole);
            ReportFeedback rfb2 = new ReportFeedback(ReportOnDialog);

            ReportFeedback rfbChain = null;

            rfbChain += rfb1;
            rfbChain += rfb2;

            Delegate[] delegates = rfbChain.GetInvocationList();
            DoubleIt   bo        = new DoubleIt();

            foreach (ReportFeedback del in delegates)
            {
                bo.DoIt(100, del);
            }
        }
Example #6
0
        public void PerformForAll()
        {
            ReportFeedback rfb1 = new ReportFeedback(ReportOnConsole);
            ReportFeedback rfb2 = new ReportFeedback(ReportOnDialog);

            //Delegate.Combine combines null and rfb1.
            //Now both rfbChain and rfb1 point to same delegate object. Please note invocation list (_invocationList) is null so far.
            //When rfbChain and rfb2 are combined, _invocationList has items pointing to rfb1 and rfb2. Now, rfbChain points to delegate object having that _invocationlist.

            ReportFeedback rfbChain = null;

            rfbChain = (ReportFeedback)Delegate.Combine(rfbChain, rfb1);
            rfbChain = (ReportFeedback)Delegate.Combine(rfbChain, rfb2);

            DoubleIt bo = new DoubleIt();

            bo.DoIt(100, rfbChain);
        }
Example #7
0
        public void PerformForNone()
        {
            DoubleIt bo = new DoubleIt();

            bo.DoIt(10, null);
        }