Exemplo n.º 1
0
        public static int Main(string[] args)
        {
            #if TEST_FIELD_WITH_INITIALIZATION
            var a = new TestClassWithFieldWithInitialization();
            var b = new TestClassWithFieldWithInitialization(a);

            Console.WriteLine(a.FInt);
            Console.WriteLine(b.FInt);
            #endif

            #if TEST_OBJECT_INITIALIZER
            int
                _b_;

            TestClassObjectInitializer
                testClassObjectInitializer = new TestClassObjectInitializer
            {
                FInt1 = IntFuncOutInt(1, out _b_),
                FInt2 = _b_
            };

            Console.WriteLine("{{FInt1: {0}, FInt2: {1}}}", testClassObjectInitializer.FInt1, testClassObjectInitializer.FInt2);

            var a = new TestClassObjectInitializerII {
                FInt1 = 1, FInt2 = 1
            };
            #endif

            #if TEST_NEW_WITH_SET
            TestClassWithSet
                testClassWithSet = new TestClassWithSet(13)
            {
                FInt = 169
            };

            testClassWithSet.FInt *= testClassWithSet.FIntRO;
            #endif

                        #if TEST_CLASS_STATIC
            TItemsInfo
                Obj1 = new TItemsInfo(),
                Obj2 = new TItemsInfo();

            Console.WriteLine(TItemsInfo.ItemsInfo.Count);
            Console.WriteLine(((SItemInfo)TItemsInfo.ItemsInfo[1]).Prop1);
            Console.WriteLine(((SItemInfo)TItemsInfo.ItemsInfo[10]).Prop2);
            // Console.WriteLine(TItemsInfo[1].Prop1);
                        #endif

                        #if CLASS_FACTORY
            ClassWithFactory
                tmpClassWithFactory = new ClassWithFactory();

            int
                i,
                j;

            for (i = 0, j = 10; i < 10; ++i, --j)
            {
                ClassWithFactory
                    anotherClassWithFactory = tmpClassWithFactory.factory(i, j);

                anotherClassWithFactory.show();
            }
                        #endif
                        #if TEST_CALL_BY
            int
                a = 15,
                b = 20;

            CallByTest
                tmpCallByTest  = new CallByTest(),
                swapCallByTest = new CallByTest();

            tmpCallByTest.a  = 300;
            tmpCallByTest.b  = 800;
            swapCallByTest.a = 13000;
            swapCallByTest.b = 26000;

            Console.WriteLine("by value (integral)");
            Console.WriteLine("Before: a={0}\tb={1}", a, b);
            tmpCallByTest.CallByValue(a, b);
            Console.WriteLine("After: a={0}\tb={1}", a, b);
            Console.WriteLine();

            Console.WriteLine("by reference (integral)");
            Console.WriteLine("Before: a={0}\tb={1}", a, b);
            tmpCallByTest.CallByReference(ref a, ref b);
            Console.WriteLine("After: a={0}\tb={1}", a, b);
            Console.WriteLine();

            Console.WriteLine("by value (reference)");
            Console.WriteLine("Before: a={0}\tb={1}", tmpCallByTest.a, tmpCallByTest.b);
            tmpCallByTest.CallWithObject(tmpCallByTest);
            Console.WriteLine("After: a={0}\tb={1}", tmpCallByTest.a, tmpCallByTest.b);
            Console.WriteLine();

            Console.WriteLine("by value (reference)");
            Console.WriteLine("Before: a={0}\tb={1}", tmpCallByTest.a, tmpCallByTest.b);
            Console.WriteLine("Before: a={0}\tb={1}", swapCallByTest.a, swapCallByTest.b);
            tmpCallByTest.swapBad(tmpCallByTest, swapCallByTest);
            Console.WriteLine("After: a={0}\tb={1}", tmpCallByTest.a, tmpCallByTest.b);
            Console.WriteLine("After: a={0}\tb={1}", swapCallByTest.a, swapCallByTest.b);
            Console.WriteLine();

            Console.WriteLine("by reference (reference)");
            Console.WriteLine("Before: a={0}\tb={1}", tmpCallByTest.a, tmpCallByTest.b);
            Console.WriteLine("Before: a={0}\tb={1}", swapCallByTest.a, swapCallByTest.b);
            tmpCallByTest.swapGood(ref tmpCallByTest, ref swapCallByTest);
            Console.WriteLine("After: a={0}\tb={1}", tmpCallByTest.a, tmpCallByTest.b);
            Console.WriteLine("After: a={0}\tb={1}", swapCallByTest.a, swapCallByTest.b);
            Console.WriteLine();
                        #endif

                        #if INHERITANCE
            #region TBase
            TBase
                BaseRef = null;                       // nothing call

            TBase
                b1 = new TBase();

            b1.WriteToLog("");

            b1.TBaseChar = '\x1';
            b1.TBaseInt  = 1;
            b1.TBaseLong = 1L;
            b1.Char      = '\x1';
            b1.Int       = 1;
            b1.Long      = 1L;
            b1.Show();
            b1.WriteToLog("");

            b1.Test();
            b1.TestTest();
            b1.TestTestTest();
            b1.WriteToLog("");

            TBase
                b2 = new TBase(b1);

            b2.WriteToLog("");

            b2.TBaseChar = '\x2';
            b2.TBaseInt  = 2;
            b2.TBaseLong = 2L;
            b2.Char      = '\x2';
            b2.Int       = 2;
            b2.Long      = 2L;
            b2.Show();
            b2.WriteToLog("");

            TBase
                b3 = b2;                  // nothing call

            b3.TBaseChar = '\x3';         // equ b2.TBaseChar='\x3';
            b3.TBaseInt  = 3;             // equ b2.TBaseInt=3;
            b3.TBaseLong = 3L;            // equ b2.TBaseLong=3L;
            b3.Char      = '\x3';         // equ b2.Char='\x3';
            b3.Int       = 3;             // equ b2.Int=3;
            b3.Long      = 3L;            // equ b2.Long=3L;
            b2.Show();
            b3.Show();
            b2.WriteToLog("");

            TBase
                b4;                         // nothing call

            b4 = b3;
            b3.Show();
            b3.WriteToLog("");
            b4.Show();
            b3 = b1;
            b1.Show();
            b3.Show();
            b1.WriteToLog("");
            b4.TBaseChar = '\x4';         // equ b2.TBaseChar='\x4';
            b4.TBaseInt  = 4;             // equ b2.TBaseInt=4;
            b4.TBaseLong = 4L;            // equ b2.TBaseLong=4L;
            b4.Char      = '\x4';         // equ b2.Char='\x4';
            b4.Int       = 4;             // equ b2.Int=4;
            b4.Long      = 4L;            // equ b2.Long=4L;
            b1.Show();
            b2.Show();
            b3.Show();
            b4.Show();
            b4.WriteToLog("");
            #endregion

            #region TDerivedBad
            TDerivedBad
                db1 = new TDerivedBad('\x1', 1, 1L, '\x1', 1, 1L, '\x1', 1, 1L);

            db1.WriteToLog("");
            db1.Show();
            db1.Test();
            db1.TestTest();
            db1.TestTestTest();
            db1.TestTestTestTest();

            TDerivedBad
                db2 = new TDerivedBad(db1);

            db2.WriteToLog("");
            db2.Show();

            TDerivedBad
                db3 = new TDerivedBad();

            db3.WriteToLog("");
            db3.Show();
            #endregion

            TDerived1
                Derived1Ref;

            TDerived1
                d11 = new TDerived1('\x1', 1, 1L, '\x1', 1, 1L, '\x1', 1, 1L);

            d11.WriteToLog("");

            d11.TDerived1Char = '\x11';
            d11.TDerived1Int  = 11;
            d11.TDerived1Long = 11L;
            d11.TBaseChar     = '\x11';
            d11.TBaseInt      = 11;
            d11.TBaseLong     = 11L;
            d11.Char          = '\x11';
            d11.Int           = 11;
            d11.Long          = 11L;
            d11.Show();

            d11.Test();
            d11.TestTest();
            d11.TestTestTest();
            d11.TestTestTestTest();
            d11.WriteToLog("");

            TDerived2
                d21 = new TDerived2('\x2', 2, 2L, '\x2', 2, 2L, '\x2', 2, 2L, '\x2', 2, 2L),
                d22 = null;

            d21.WriteToLog("");

            d21.TDerived2Char = '\x21';
            d21.TDerived2Int  = 21;
            d21.TDerived2Long = 21L;
            d21.TDerived1Char = '\x21';
            d21.TDerived1Int  = 21;
            d21.TDerived1Long = 21L;
            d21.TBaseChar     = '\x21';
            d21.TBaseInt      = 21;
            d21.TBaseLong     = 21L;
            d21.Char          = '\x21';
            d21.Int           = 21;
            d21.Long          = 21L;

            d21.Test();
            d21.TestTest();
            d21.TestTestTest();
            d21.TestTestTestTest();
            d21.WriteToLog("");

            BaseRef = b1;
            BaseRef.WriteToLog(string.Format("BaseRef.GetType() = \"{0}\"", BaseRef.GetType()));
            BaseRef.WriteToLog(string.Format("null {0}is TBase", null is TBase ? string.Empty : "!"));
            BaseRef.WriteToLog(string.Format("BaseRef {0}is TBase", BaseRef is TBase ? string.Empty : "!"));
            BaseRef.WriteToLog(string.Format("BaseRef {0}is TDerivedBad", BaseRef is TDerivedBad ? string.Empty : "!"));
            BaseRef.WriteToLog(string.Format("BaseRef {0}is TDerived1", BaseRef is TDerived1 ? string.Empty : "!"));
            BaseRef.WriteToLog(string.Format("BaseRef {0}is TDerived2", BaseRef is TDerived2 ? string.Empty : "!"));
            BaseRef.Test();
            BaseRef.TestTest();
            BaseRef.TestTestTest();
            BaseRef.WriteToLog("");

            BaseRef = db1;
            BaseRef.WriteToLog(string.Format("BaseRef.GetType() = \"{0}\"", BaseRef.GetType()));
            BaseRef.WriteToLog(string.Format("BaseRef {0}is TBase", BaseRef is TBase ? string.Empty : "!"));
            BaseRef.WriteToLog(string.Format("BaseRef {0}is TDerivedBad", BaseRef is TDerivedBad ? string.Empty : "!"));
            BaseRef.WriteToLog(string.Format("BaseRef {0}is TDerived1", BaseRef is TDerived1 ? string.Empty : "!"));
            BaseRef.WriteToLog(string.Format("BaseRef {0}is TDerived2", BaseRef is TDerived2 ? string.Empty : "!"));
            BaseRef.Test();
            BaseRef.TestTest();
            BaseRef.TestTestTest();
            BaseRef.WriteToLog("");

            BaseRef = d11;
            BaseRef.WriteToLog(string.Format("BaseRef.GetType() = \"{0}\"", BaseRef.GetType()));
            BaseRef.WriteToLog(string.Format("BaseRef {0}is TBase", BaseRef is TBase ? string.Empty : "!"));
            BaseRef.WriteToLog(string.Format("BaseRef {0}is TDerivedBad", BaseRef is TDerivedBad ? string.Empty : "!"));
            BaseRef.WriteToLog(string.Format("BaseRef {0}is TDerived1", BaseRef is TDerived1 ? string.Empty : "!"));
            BaseRef.WriteToLog(string.Format("BaseRef {0}is TDerived2", BaseRef is TDerived2 ? string.Empty : "!"));
            BaseRef.Test();
            BaseRef.TestTest();
            BaseRef.TestTestTest();
            BaseRef.WriteToLog("");

            Type
                tmpType = BaseRef.GetType();

            BaseRef = d21;
            BaseRef.WriteToLog(string.Format("BaseRef.GetType() = \"{0}\"", BaseRef.GetType()));
            BaseRef.WriteToLog(string.Format("BaseRef {0}is TBase", BaseRef is TBase ? string.Empty : "!"));
            BaseRef.WriteToLog(string.Format("BaseRef {0}is TDerivedBad", BaseRef is TDerivedBad ? string.Empty : "!"));
            BaseRef.WriteToLog(string.Format("BaseRef {0}is TDerived1", BaseRef is TDerived1 ? string.Empty : "!"));
            BaseRef.WriteToLog(string.Format("BaseRef {0}is TDerived2", BaseRef is TDerived2 ? string.Empty : "!"));
            BaseRef.WriteToLog(string.Format("{0}typeof(TBase).IsInstanceOfType(BaseRef)", typeof(TBase).IsInstanceOfType(BaseRef) ? string.Empty : "!"));
            BaseRef.WriteToLog(string.Format("{0}typeof(TDerivedBad).IsInstanceOfType(BaseRef)", typeof(TDerivedBad).IsInstanceOfType(BaseRef) ? string.Empty : "!"));
            BaseRef.WriteToLog(string.Format("{0}typeof(TDerived1).IsInstanceOfType(BaseRef)", typeof(TDerived1).IsInstanceOfType(BaseRef) ? string.Empty : "!"));
            BaseRef.WriteToLog(string.Format("{0}typeof(TDerived2).IsInstanceOfType(BaseRef)", typeof(TDerived2).IsInstanceOfType(BaseRef) ? string.Empty : "!"));
            BaseRef.Test();
            BaseRef.TestTest();
            BaseRef.TestTestTest();
            BaseRef.WriteToLog("");

            Derived1Ref = d11;
            Derived1Ref.WriteToLog(string.Format("Derived1Ref.GetType() = \"{0}\"", Derived1Ref.GetType()));
            Derived1Ref.WriteToLog(string.Format("Derived1Ref {0}is TBase", Derived1Ref is TBase ? string.Empty : "!"));
            Derived1Ref.WriteToLog(string.Format("Derived1Ref {0}is TDerivedBad", Derived1Ref is TDerivedBad ? string.Empty : "!"));
            Derived1Ref.WriteToLog(string.Format("Derived1Ref {0}is TDerived1", Derived1Ref is TDerived1 ? string.Empty : "!"));
            Derived1Ref.WriteToLog(string.Format("Derived1Ref {0}is TDerived2", Derived1Ref is TDerived2 ? string.Empty : "!"));
            Derived1Ref.Test();
            Derived1Ref.TestTest();
            Derived1Ref.TestTestTest();
            Derived1Ref.TestTestTestTest();
            Derived1Ref.WriteToLog("");

            Derived1Ref = d21;
            Derived1Ref.WriteToLog(string.Format("Derived1Ref.GetType() = \"{0}\"", Derived1Ref.GetType()));
            Derived1Ref.WriteToLog(string.Format("Derived1Ref {0}is TBase", Derived1Ref is TBase ? string.Empty : "!"));
            Derived1Ref.WriteToLog(string.Format("Derived1Ref {0}is TDerivedBad", Derived1Ref is TDerivedBad ? string.Empty : "!"));
            Derived1Ref.WriteToLog(string.Format("Derived1Ref {0}is TDerived1", Derived1Ref is TDerived1 ? string.Empty : "!"));
            Derived1Ref.WriteToLog(string.Format("Derived1Ref {0}is TDerived2", Derived1Ref is TDerived2 ? string.Empty : "!"));
            Derived1Ref.Test();
            Derived1Ref.TestTest();
            Derived1Ref.TestTestTest();
            Derived1Ref.TestTestTestTest();
            Derived1Ref.WriteToLog("");

            object tmpObject = d21;
            var    tmpVar    = tmpObject as TBase;
            tmpType = tmpVar.GetType();
                        #endif

                        #if TEST_CYCLE
            ArrayList
                al = new ArrayList();

            al.Add("First");
            al.Add("Second");
            al.Add("Third");
            al.Add("Fourth");
            al.Add("Fifth");
            al.Add("Sixth");
            al.Add("Seventh");
            al.Add("Eighth");
            al.Add("Ninth");

            foreach (string s in al)
            {
                ClassSimple
                            tmpClassSimple;

                string
                    tmpString;

                tmpClassSimple = new ClassSimple(s);
                tmpString      = tmpClassSimple.A;
            }
                        #endif

            return(0);
        }
Exemplo n.º 2
0
 public TestClassObjectInitializerII(TestClassObjectInitializerII obj)
 {
     _fInt1 = obj.FInt1;
     _fInt2 = obj.FInt2;
     Console.WriteLine("TestClassObjectInitializerII::.ctor(TestClassObjectInitializerII)");
 }