Esempio n. 1
0
        public void Run()
        {
            char[] helloWorld = new char[] {'H', 'e'};
            
            var my1 = new MyString(helloWorld).ToUpper().ToString(); // result: HE
            var my2 = new MyString(helloWorld).ToString(); // result: He

            string testString = "String ";
            Note[] myNoteArray = new Note[3];

            for (int i = 0; i < 3; i++)
            {
                string docText = testString + i.ToString();
                if (i % 2 == 0)
                {
                    Document myDocument = new Document(docText, (i + 5) * 10);
                    myNoteArray[i] = myDocument;
                }
                else
                {
                    Note myNote = new Note(docText);
                    myNoteArray[i] = myNote;
                }
            }

            foreach (Note theNote in myNoteArray)
            {
                Console.WriteLine("\nTesting {0} with IS", theNote);

                theNote.Read();     // all notes can do this
                if (theNote is ICompressible)
                {
                    ICompressible myCompressible = theNote as ICompressible;
                    myCompressible.Compress();
                }
                else
                {
                    Console.WriteLine("This storable object is not compressible.");
                }

                if (theNote is Document)
                {
                    Document myDoc = theNote as Document;

                    // clean cast
                    myDoc = theNote as Document;
                    Console.WriteLine("my documentID is {0}", myDoc.ID);
                }
            }

            foreach (Note theNote in myNoteArray)
            {
                Console.WriteLine("\nTesting {0} with AS", theNote);
                ICompressible myCompressible = theNote as ICompressible;
                if (myCompressible != null)
                {
                    myCompressible.Compress();
                }
                else
                {
                    Console.WriteLine("This storable object is not compressible.");
                }    // end else

                Document theDoc = theNote as Document;
                if (theDoc != null)
                {
                    Console.WriteLine("My documentID is {0}",  ((Document)theNote).ID);
                }
                else
                {
                    Console.WriteLine("Not a document.");
                }
            }
        }
Esempio n. 2
0
        public void Run()
        {
            char[] helloWorld = new char[] { 'H', 'e' };

            var my1 = new MyString(helloWorld).ToUpper().ToString(); // result: HE
            var my2 = new MyString(helloWorld).ToString();           // result: He

            string testString = "String ";

            Note[] myNoteArray = new Note[3];

            for (int i = 0; i < 3; i++)
            {
                string docText = testString + i.ToString();
                if (i % 2 == 0)
                {
                    Document myDocument = new Document(docText, (i + 5) * 10);
                    myNoteArray[i] = myDocument;
                }
                else
                {
                    Note myNote = new Note(docText);
                    myNoteArray[i] = myNote;
                }
            }

            foreach (Note theNote in myNoteArray)
            {
                Console.WriteLine("\nTesting {0} with IS", theNote);

                theNote.Read();     // all notes can do this
                if (theNote is ICompressible)
                {
                    ICompressible myCompressible = theNote as ICompressible;
                    myCompressible.Compress();
                }
                else
                {
                    Console.WriteLine("This storable object is not compressible.");
                }

                if (theNote is Document)
                {
                    Document myDoc = theNote as Document;

                    // clean cast
                    myDoc = theNote as Document;
                    Console.WriteLine("my documentID is {0}", myDoc.ID);
                }
            }

            foreach (Note theNote in myNoteArray)
            {
                Console.WriteLine("\nTesting {0} with AS", theNote);
                ICompressible myCompressible = theNote as ICompressible;
                if (myCompressible != null)
                {
                    myCompressible.Compress();
                }
                else
                {
                    Console.WriteLine("This storable object is not compressible.");
                }    // end else

                Document theDoc = theNote as Document;
                if (theDoc != null)
                {
                    Console.WriteLine("My documentID is {0}", ((Document)theNote).ID);
                }
                else
                {
                    Console.WriteLine("Not a document.");
                }
            }
        }