Пример #1
0
            public void secondGenericFunc(T1 t1, T2 t2)
            {
                genericFunc(t2);
                TestGeneric <T1> tg1 = new TestGeneric <T1>(null);

                tg1.genericFunc(t1);
            }
Пример #2
0
        public void TestRaiseGeneric()
        {
            TestGeneric += TestEvent_TestGeneric;

            // test static method
            m_calls     = 0;
            m_eventArgs = new EventArgs();
            Event.Raise <EventArgs>(TestGeneric, this, m_eventArgs);
            Assert.True(m_calls == 1);

            // test extension method
            m_calls     = 0;
            m_eventArgs = new EventArgs();
            TestGeneric.Raise(this, m_eventArgs);
            Assert.True(m_calls == 1);
        }
Пример #3
0
        void Start()
        {
            if (monkey != null)
            {
                monkey(0);
            }
            TestClass i1 = new TestClass2();

            i1.overrideme();
            i1.overrideme3();
            i1.normal2();
            TestStruct i2 = new TestStruct();

            i2.overrideme();
            i2.overrideme2();
            doit(i1, i2, i1);
            doit(i2, i2, i1);
            callints(i2, i2, i1);
            int res = 0;

            for (int i = 0; i < intArray.Length; i++)
            {
                res += intArray[i];
            }
            for (int i = 0; i < objArray.Length; i++)
            {
                res += (int)objArray[i];
            }
            ITestGeneric <int>    x1 = new TestGeneric <int>(new int[] { 1, 2, 3 });
            ITestGeneric <object> x2 = new TestGeneric <object>(new object[] { new object() });

            callgeneric(x1, 0);
            callgeneric(x2, "foo");
            ITestGeneric <string> x3 = new TestGeneric2 <int, string>(new string[] { "as", "de" });

            new WeirdLayout2().f = 3;
            x3.genericFunc("bar");
        }
        public void TestSetterGenericStruct()
        {
            TestGeneric <int, int> testGeneric = new TestGeneric <int, int>();

            testGeneric.key = 10;
            testGeneric.Val = 50;

            var genericMembers = testGeneric.GetType().GetMembers(
                BindingFlags.NonPublic |
                BindingFlags.Public |
                BindingFlags.Instance)
                                 .Where(x => x.MemberType == MemberTypes.Field)
                                 .Cast <FieldInfo>().ToList();


            foreach (var member in genericMembers)
            {
                var action = ReflectionUtils.CreateInstanceFieldSetterForValueType(member);
                testGeneric = (TestGeneric <int, int>)action.Invoke(testGeneric, 90);
            }

            Assert.AreEqual(testGeneric.key, 90);
            Assert.AreEqual(testGeneric.Val, 90);
        }