コード例 #1
0
        public void ExtendedType_CanDisambiguateMembers()
        {
            ExtendedType et = ExtendedType.Get(typeof(ComplexOverloads <>));

            IEnumerable <Method> methods = et.GetMethods("A");

            Assert.IsNotNull(methods);
            Assert.AreEqual(8, methods.Count()); //Assert.AreEqual(9, methods.Count());

            Method invalidMethod = et.GetMethod("A");

            Assert.IsNull(invalidMethod);

            Method method1 = et.GetMethod("A", TypeSearch.T1);

            Assert.IsNotNull(method1);
            Assert.IsTrue(method1.Info.ContainsGenericParameters);

            // Demonstrate cast to void
            bool[] castsRequired;
            invalidMethod = et.GetMethod("A", 0, true, true, out castsRequired, TypeSearch.Void);
            Assert.IsNotNull(invalidMethod);
            Assert.IsTrue(castsRequired[0]);

            Method method2 = et.GetMethod("A", typeof(int), TypeSearch.Void);

            Assert.IsNotNull(method2);
            Assert.AreNotEqual(method1, method2);

            Method method3 = et.GetMethod("A", typeof(int).MakeByRefType(), TypeSearch.Void);

            Assert.IsNotNull(method3);
            Assert.AreNotEqual(method3, method1);
            Assert.AreNotEqual(method3, method2);

            /*
             * Method method3b = et.GetMethod("A", typeof (int).MakePointerType(), TypeSearch.Void);
             * Assert.IsNotNull(method3b);
             * Assert.AreNotEqual(method3b, method1);
             * Assert.AreNotEqual(method3b, method2);*/

            Method method4 = et.GetMethod("A", typeof(string), typeof(string), TypeSearch.Void);

            Assert.IsNotNull(method4);
            Assert.IsTrue(method4.Info.IsStatic);
            Assert.AreNotEqual(method4, method1);
            Assert.AreNotEqual(method4, method2);
            Assert.AreNotEqual(method4, method3);

            Method method5 = et.GetMethod("A", typeof(string), typeof(string).MakeByRefType(), TypeSearch.Void);

            Assert.IsNotNull(method5);
            Assert.AreNotEqual(method5, method1);
            Assert.AreNotEqual(method5, method2);
            //Assert.AreNotEqual(method5, method3b);
            Assert.AreNotEqual(method5, method4);

            Method method6 = et.GetMethod("A", 1, typeof(string), TypeSearch.Void);

            Assert.IsNotNull(method6);
            Assert.AreNotEqual(method6, method1);
            Assert.AreNotEqual(method6, method2);
            //Assert.AreNotEqual(method6, method3b);
            Assert.AreNotEqual(method6, method4);
            Assert.AreNotEqual(method6, method5);

            Method method7 = et.GetMethod("A", 2, typeof(string), TypeSearch.Void);

            Assert.IsNotNull(method7);
            Assert.AreNotEqual(method7, method1);
            Assert.AreNotEqual(method7, method2);
            //Assert.AreNotEqual(method7, method3b);
            Assert.AreNotEqual(method7, method4);
            Assert.AreNotEqual(method7, method5);
            Assert.AreNotEqual(method7, method6);

            Method method8 = et.GetMethod(
                "A",
                1,
                new TypeSearch(GenericArgumentLocation.Type, "T"),
                new TypeSearch(GenericArgumentLocation.Signature, 0, true),
                TypeSearch.Void);

            Assert.IsNotNull(method8);
        }