コード例 #1
0
    public static void MainD(string[] args)
    {
        BaseClass1    bc   = new BaseClass1();
        DerivedClass1 dc   = new DerivedClass1();
        BaseClass1    bcdc = new DerivedClass1();

        // The following two calls do what you would expect. They call
        // the methods that are defined in BaseClass.
        bc.Method1();
        bc.Method2();
        // Output:
        // Base - Method1
        // Base - Method2

        // The following two calls do what you would expect. They call
        // the methods that are defined in DerivedClass.
        dc.Method1();
        dc.Method2();
        // Output:
        // Derived - Method1
        // Derived - Method2

        // The following two calls produce different results, depending
        // on whether override (Method1) or new (Method2) is used.
        bcdc.Method1();
        bcdc.Method2();
        // Output:
        // Derived - Method1
        // Base - Method2
    }
コード例 #2
0
        static void Main(string[] args)
        {
            IStuff IStuff = new DerivedClass1("data1 here");

            IStuff.DoStuff(); // prints "1: data here"
            IStuff = new DerivedClass2("data2 here");
            IStuff.DoStuff(); // prints "1: data here"
            Console.ReadKey();
        }
コード例 #3
0
ファイル: N522.cs プロジェクト: TinkerWorX/Bridge
        public static void TestUseCase1()
        {
            var dc1 = new DerivedClass1();
            dc1.AddValue(5);

            Assert.AreEqual(dc1.GetValues().Count, 1, "Bridge522 dc1.Count = 1");

            var dc2 = new DerivedClass1();
            Assert.AreEqual(dc2.GetValues().Count, 0, "Bridge522 dc2.Count = 0");
        }
コード例 #4
0
        static void SwapAndVirtualCalls()
        {
            BaseClass a = new DerivedClass1();
            BaseClass b = new DerivedClass2();

            for (int i = 0; i < 50000; i++)
            {
                a.Test();
                Swap(ref a, ref b);
            }
        }
コード例 #5
0
        public static void TestUseCase1()
        {
            var dc1 = new DerivedClass1();

            dc1.AddValue(5);

            Assert.AreEqual(1, dc1.GetValues().Count, "Bridge522 dc1.Count = 1");

            var dc2 = new DerivedClass1();

            Assert.AreEqual(0, dc2.GetValues().Count, "Bridge522 dc2.Count = 0");
        }
コード例 #6
0
        public static void TestUseCase1(Assert assert)
        {
            assert.Expect(2);

            var dc1 = new DerivedClass1();

            dc1.AddValue(5);

            assert.Equal(dc1.GetValues().Count, 1, "Bridge522 dc1.Count = 1");

            var dc2 = new DerivedClass1();

            assert.Equal(dc2.GetValues().Count, 0, "Bridge522 dc2.Count = 0");
        }
コード例 #7
0
        public void FindClass_BaseDerived_Base()
        {
            var foo1 = new DerivedClass1 {
                Foo = "bar"
            };
            var foo2 = new DerivedClass2 {
                Foo = "baz"
            };

            var expression1 = (Expression <Func <object> >)(() => foo1.Foo);
            var expression2 = (Expression <Func <object> >)(() => foo2.Foo);

            var(type, instance) = ClassFinder.FindClass(expression2);

            Assert.AreEqual(typeof(DerivedClass2), type);
            Assert.AreSame(foo2, instance);
        }
コード例 #8
0
        public void Issue291Test2Attr([IncludeDataSources(TestProvName.AllSQLite)] string context)
        {
            using (var db = GetDataContext(context, new MappingSchema()))
            {
                db.MappingSchema.GetFluentMappingBuilder()

                .Entity <BaseClass>().HasTableName("my_table")
                .HasAttribute(new LinqToDB.Mapping.InheritanceMappingAttribute()
                {
                    IsDefault = true,
                    Type      = typeof(DerivedClass),
                    Code      = GenericItemType.DerivedClass
                })
                .HasAttribute(new LinqToDB.Mapping.InheritanceMappingAttribute()
                {
                    Type = typeof(DerivedClass1),
                    Code = GenericItemType.DerivedClass1
                })
                .Property(t => t.MyCol1).HasColumnName("my_col1")
                .Property(t => t.NotACol).IsNotColumn()

                .Entity <DerivedClass>().Property(t => t.SomeOtherField).HasColumnName("my_other_col")
                .Entity <DerivedClass1>().Property(t => t.SomeOtherField).HasColumnName("my_other_col");

                using (db.CreateLocalTable <DerivedClass>())
                {
                    DerivedClass item = new DerivedClass {
                        NotACol = "test", MyCol1 = "MyCol1"
                    };
                    db.Insert(item);
                    DerivedClass1 item1 = new DerivedClass1 {
                        NotACol = "test"
                    };
                    db.Insert(item1);

                    DerivedClass res   = db.GetTable <DerivedClass>().FirstOrDefault();
                    var          count = db.GetTable <DerivedClass>().Count();

                    Assert.AreEqual(item.MyCol1, res.MyCol1);
                    Assert.AreNotEqual(item.NotACol, res.NotACol);
                    Assert.AreEqual(1, count);
                }
            }
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: oneananda/C_Sharp_Examples
        static void Main(string[] args)
        {
            BaseClass1 BC1Obj = new BaseClass1();

            Console.WriteLine();


            BaseClass1 BC1Obj2 = new DerivedClass1();

            Console.WriteLine();


            DerivedClass1 DC1Obj1 = new DerivedClass1();

            Console.WriteLine();


            Console.ReadLine();
        }