Пример #1
0
        public static void TestUniversalGenericThatUsesCanonicalGenericType()
        {
            {
                var t = TypeOf.PUG_UseCanonGenericTypeFromUniversalGenericClassType3.MakeGenericType(typeof(DerivedClass3), TypeOf.Double);
                ITest <DerivedClass3> b = (ITest <DerivedClass3>)Activator.CreateInstance(t);

                DerivedClass3 data = new DerivedClass3("abc");
                Assert.AreEqual("DerivedClass3.abc", b.TestMethod(data).ToString());
            }

            {
                var t = TypeOf.PUG_UseCanonGenericTypeFromUniversalGenericClassType5.MakeGenericType(typeof(MyStruct5), TypeOf.Double);
                ITest <MyStruct5> b = (ITest <MyStruct5>)Activator.CreateInstance(t);

                MyStruct5 data = new MyStruct5("123");
                Assert.AreEqual("MyStruct5.123", b.TestMethod(data).ToString());
            }

            {
                var t = TypeOf.PUG_UseCanonGenericTypeFromUniversalGenericClassType6.MakeGenericType(typeof(MyStruct6), TypeOf.Double);
                ITest <MyStruct6> b = (ITest <MyStruct6>)Activator.CreateInstance(t);

                MyStruct6 data = new MyStruct6("456");
                Assert.AreEqual("MyStruct6.456", b.TestMethod(data).ToString());
            }
        }
Пример #2
0
        public static void TestUniversalGenericThatUsesCanonicalGenericMethodWithConstraints()
        {
            var t = TypeOf.PUG_UseCanonGenericMethodFromUniversalGenericClassType4.MakeGenericType(typeof(DerivedClass3), TypeOf.Double);
            ITest <DerivedClass3> b = (ITest <DerivedClass3>)Activator.CreateInstance(t);

            DerivedClass3 data = new DerivedClass3("def");

            Assert.AreEqual("DerivedClass3.def", b.TestMethod(data).ToString());
        }