public string ProcessWithArray(string data, NumberPrinter printer)
 {
     Delta        = double.Parse(DisplayDelta, NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture);
     MinimumValue = double.Parse(DisplayMinimumValue, NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture);
     _parser      = new CollectingFinder(Litera, Delta, printer, MinimumValue, LoggingDelegate);
     return(_parser.Process(data));
 }
Beispiel #2
0
    public static void Main(string[] args)
    {
        NumberPrinter a = PrintNumber;
        object        b = a;

        var c = (b as NumberPrinter);

        a(1);
        c(2);
    }
        public string InitArrayProcessLogic(string data, NumberPrinter printer)
        {
            var _currentParser = (_parser as CollectingFinder);

            _currentParser.DoTransform();
            StubValueDictionary = _currentParser.GetCoordinateArray();
            foreach (string key in StubValueDictionary.Keys)
            {
                data = data.Replace(key, printer.Print(StubValueDictionary[key]));
            }
            return(data);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            try
            {
                #region TestUsageOfOperatorOverload
                Rettangolo A = new Rettangolo(3, 4);
                Rettangolo B = new Rettangolo(5, 5);
                Rettangolo C = A + B;
                Console.WriteLine("Area rettangolo A ({0}x{1}): {2}\nArea rettangolo B ({3}x{4}): {5}\nArea A+B ({6}x{7}): {8}", A.L, A.H, A.GetArea(), B.L, B.H, B.GetArea(), C.L, C.H, C.GetArea());
                #endregion

                #region TestOfUsageOfDelegateFunction
                Utility.Separatore();
                Console.WriteLine("Test di utilizzo di una funzione delegata:");
                NumberChanger NC1 = new NumberChanger(TestDelegate.AddNum);
                NumberChanger NC2 = new NumberChanger(TestDelegate.MultNum);
                Console.WriteLine("- valore iniziale: {0}", TestDelegate.GetNum());
                int plus = 25;
                NC1(plus);
                Console.WriteLine("- dopo aggiunta di {0}: {1}", plus, TestDelegate.GetNum());
                int multi = 5;
                NC2(multi);
                Console.WriteLine("- dopo moltiplicazione per {0}: {1}", multi, TestDelegate.GetNum());
                /* resetto il numero */
                NC2(0);
                Console.WriteLine("- dopo aver resettato il numero: {0}", TestDelegate.GetNum());
                NumberChanger NC;
                NC = NC1 + NC2;
                NC(5);
                Console.WriteLine("- dopo multicasting (NC = NC1 + NC2): {0}", TestDelegate.GetNum());
                Console.WriteLine();
                Console.WriteLine("Altro test di utilizzo di un delegato:");
                string      SDel = "Logga questo";
                PrintString PSO  = new PrintString(TestDelegateLog.VideoOutput);
                PrintString PSF  = new PrintString(TestDelegateLog.FileOutput);
                PrintString Log  = PSO + PSF;
                Log(SDel);
                Console.WriteLine("(la stringa qui sopra è stata mostrata a video e loggata in un file simultaneamente attraverso l'utilizzo di un delegato multicast)");
                NumberPrinter NP = delegate(int n)
                {
                    Console.WriteLine("Altro test: il numero {0} è stato scritto con un delegato anonimo!", n);
                };
                NP(0);
                NP(1);
                NP(2);
                #endregion

                #region TestOfUsageOfEvents
                Utility.Separatore();
                Console.WriteLine("Test di utilizzo di eventi (con delegati):");
                EventTest EV = new EventTest();
                EV.OnPrint += EventTest_OnPrint;
                EV.Print("Uallabalooza");
                #endregion

                #region TestOfUsageOfGenerics
                Utility.Separatore();
                GenericArray <string> SArr = new GenericArray <string>(5);
                Console.WriteLine("Test di utilizzo dei GENERICS di tipo \"{0}\":", SArr.TypeOf());
                SArr.Add(0, "Ualla");
                SArr.Add(1, "Balooza");
                SArr.Add(2, "In");
                SArr.Add(3, "The");
                SArr.Add(4, "Sky");
                for (var i = 0; i < SArr.Size; i++)
                {
                    Console.WriteLine("- indice {0}: \"{1}\"", i, SArr.Get(i));
                }
                #endregion

                #region TestOfUsageOfUnsafeCode

                /* i puntatori vanno usati solo nei blocchi di codice "unsafe";
                 * puoi dichiarare unsafe anche una funzione o un metodo, se deve usare puntatori;
                 * occorre permettere la compilazione di codice unsafe dalle impostazioni del progetto */
                unsafe
                {
                    Utility.Separatore();
                    Console.WriteLine("Test di utilizzo di puntatori in codice UNSAFE:");
                    int  SUns  = 12345;
                    int *pSUns = &SUns;
                    Console.WriteLine("- valore: {0}", SUns);
                    Console.WriteLine("- valore da puntatore: {0}", pSUns->ToString());
                    Console.WriteLine("- indirizzo della variabile: {0}", (int)pSUns);
                    Console.WriteLine();
                    int  SUns2  = 54321;
                    int *pSUns2 = &SUns2;
                    Console.WriteLine("Prima dello SWAP dei due puntatori: {0} - {1}", SUns, SUns2);
                    Swap(pSUns, pSUns2);
                    Console.WriteLine("Dopo lo SWAP dei due puntatori: {0} - {1}", SUns, SUns2);
                    Console.WriteLine();
                    Console.WriteLine("Test di accesso array con puntatori:");
                    int[] Arr = new int[] { 10, 20, 30 };
                    fixed(int *pArr = Arr)
                    for (int i = 0; i < Arr.Length; i++)
                    {
                        Console.WriteLine("- Indirizzo di Arr[{0}]: {1}; Valore di Arr[{0}]: {2}", i, (int)(pArr + i), *(pArr + i));
                    }
                }
                #endregion

                #region TestOfUsageOfThreads
                Utility.Separatore();
                Console.WriteLine("Test di utilizzo dei THREAD");
                Thread TH = Thread.CurrentThread;
                TH.Name = "ThreadMain";
                Console.WriteLine("Nome del thread corrente: {0}", TH.Name);
                ThreadStart TS = new ThreadStart(ThreadSingolo);
                Console.WriteLine("Creazione in corso di un thread figlio...");
                Thread Child = new Thread(TS);
                Child.Start();
                int SleepTime = 5000;
                Console.WriteLine("Metto in pausa per {0} secondi...", SleepTime / 1000);
                Thread.Sleep(SleepTime);
                Console.WriteLine("Riprendo l'esecuzione!");

                /*Console.WriteLine("Esco dall'esecuzione del thread (metodo Abort())...");
                 * Child.Abort();*/ /* non usare Child.Abort! usa Child.Interrupt quando è in stato di sleep-wait-join */
                #endregion
            }
            #region catch

            /*catch(ThreadAbortException e)
             * {
             *  Console.WriteLine("Thread distrutto! (metodo Abort())");
             * }*/
            catch (Exception e)
            {
                Utility.MostraEccezione <Exception>(e);
            }
            #endregion

            Console.ReadKey();
        }