Exemple #1
0
 public void TestIterative()
 {
     AssertExt.AreEqual(new int[0], new int[0].Iterative().ToArray());
     AssertExt.AreEqual(new int[0], new int[] { 0, 1, 2, 3 }.Iterative().ToArray());
     AssertExt.AreEqual(new int[] { 0 }, new int[] { 0, 0, 0, 0 }.Iterative().ToArray());
     AssertExt.AreEqual(new int[] { 0, 1, 2 }, new int[] { 0, 0, 1, 1, 2, 2 }.Iterative().ToArray());
     AssertExt.AreEqual(new int[] { 1, 2, 0 }, new int[] { 0, 1, 1, 2, 2, 3, 4, 5, 6, 0 }.Iterative().ToArray());
 }
Exemple #2
0
        public void TestMakeGenericMethodFromParams()
        {
            Type       type   = typeof(TestClass);
            MethodInfo method = type.GetMethod("TestMethod");

            AssertExt.AreEqual(new Type[] { typeof(int) }, method.GenericArgumentsInferences(typeof(int)));
            AssertExt.AreEqual(new Type[] { typeof(uint) }, method.GenericArgumentsInferences(typeof(uint)));
            method = type.GetMethod("TestMethod2");
            AssertExt.AreEqual(new Type[] { typeof(int) }, method.GenericArgumentsInferences(typeof(int)));
            AssertExt.AreEqual(new Type[] { typeof(uint) }, method.GenericArgumentsInferences(typeof(uint)));
            method = type.GetMethod("TestMethod3");
            AssertExt.AreEqual(new Type[] { typeof(int) },
                               method.GenericArgumentsInferences(typeof(int), typeof(int)));
            AssertExt.AreEqual(new Type[] { typeof(object) },
                               method.GenericArgumentsInferences(typeof(string), typeof(object)));
            AssertExt.AreEqual(new Type[] { typeof(IList <int>) },
                               method.GenericArgumentsInferences(typeof(int[]), typeof(IList <int>)));
            AssertExt.AreEqual(new Type[] { typeof(IList <int>) },
                               method.GenericArgumentsInferences(typeof(IList <int>), typeof(int[])));
            AssertExt.AreEqual(null, method.GenericArgumentsInferences(typeof(uint), typeof(string)));
            method = type.GetMethod("TestMethod4");
            AssertExt.AreEqual(new Type[] { typeof(int) },
                               method.GenericArgumentsInferences(typeof(int), typeof(int)));
            AssertExt.AreEqual(new Type[] { typeof(IList <int>) },
                               method.GenericArgumentsInferences(typeof(IList <int>), typeof(int[])));
            AssertExt.AreEqual(null, method.GenericArgumentsInferences(typeof(int[]), typeof(IList <int>)));
            AssertExt.AreEqual(null, method.GenericArgumentsInferences(typeof(string), typeof(object)));
            AssertExt.AreEqual(null, method.GenericArgumentsInferences(typeof(uint), typeof(string)));
            method = type.GetMethod("TestMethod5");
            AssertExt.AreEqual(new Type[] { typeof(int) }, method.GenericArgumentsInferences(typeof(int[]), typeof(int)));
            AssertExt.AreEqual(new Type[] { typeof(long) }, method.GenericArgumentsInferences(typeof(long[]), typeof(int)));
            method = type.GetMethod("TestMethod6");
            AssertExt.AreEqual(new Type[] { typeof(int), typeof(string) },
                               method.GenericArgumentsInferences(typeof(List <IDictionary <int, string> >), typeof(IList <int[]>)));
            AssertExt.AreEqual(null,
                               method.GenericArgumentsInferences(typeof(List <Dictionary <int, string> >), typeof(IList <long[]>)));
            method = type.GetMethod("TestMethod7");
            AssertExt.AreEqual(new Type[] { typeof(int), typeof(string) },
                               method.GenericArgumentsInferences(typeof(List <IDictionary <int, string> >), typeof(IList <int[]>)));
            AssertExt.AreEqual(new Type[] { typeof(int), typeof(string) },
                               method.GenericArgumentsInferences(typeof(List <Dictionary <int, string> >), typeof(IList <int[]>)));
            AssertExt.AreEqual(null,
                               method.GenericArgumentsInferences(typeof(List <Dictionary <int, string> >), typeof(IList <long[]>)));
            method = type.GetMethod("TestMethod8");
            AssertExt.AreEqual(new Type[] { typeof(int) },
                               method.GenericArgumentsInferences(typeof(int), typeof(int), typeof(int), typeof(int)));
            AssertExt.AreEqual(new Type[] { typeof(string) },
                               method.GenericArgumentsInferences(typeof(string), typeof(string), typeof(object), typeof(object)));
            AssertExt.AreEqual(new Type[] { typeof(string) },
                               method.GenericArgumentsInferences(typeof(string), typeof(string[])));
            AssertExt.AreEqual(new Type[] { typeof(string[]) },
                               method.GenericArgumentsInferences(typeof(string[]), typeof(string[])));
            AssertExt.AreEqual(new Type[] { typeof(string[][]) },
                               method.GenericArgumentsInferences(typeof(string[][]), typeof(string[][])));
            AssertExt.AreEqual(new Type[] { typeof(string[]) },
                               method.GenericArgumentsInferences(typeof(string[]), typeof(string[][])));
            AssertExt.AreEqual(new Type[] { typeof(string) },
                               method.GenericArgumentsInferences(typeof(string), typeof(string)));
            AssertExt.AreEqual(new Type[] { typeof(string) }, method.GenericArgumentsInferences(typeof(string)));
            method = type.GetMethod("TestMethod9");
            AssertExt.AreEqual(new Type[] { typeof(int), typeof(string) },
                               method.GenericArgumentsInferences(typeof(Func <int, string>), typeof(int), typeof(string)));
            AssertExt.AreEqual(new Type[] { typeof(TestClass2), typeof(string) },
                               method.GenericArgumentsInferences(typeof(Func <TestClass2, string>), typeof(TestClass3), typeof(string)));
            AssertExt.AreEqual(null,
                               method.GenericArgumentsInferences(typeof(Func <short, string>), typeof(int), typeof(string)));
            AssertExt.AreEqual(new Type[] { typeof(object), typeof(string) },
                               method.GenericArgumentsInferences(typeof(Func <object, string>), typeof(string), typeof(string)));
            AssertExt.AreEqual(new Type[] { typeof(int), typeof(string) },
                               method.GenericArgumentsInferences(typeof(Func <int, string>), typeof(short), typeof(string)));
            AssertExt.AreEqual(new Type[] { typeof(int), typeof(object) },
                               method.GenericArgumentsInferences(typeof(Func <int, string>), typeof(short), typeof(object)));
            AssertExt.AreEqual(new Type[] { typeof(IList <int>), typeof(object) },
                               method.GenericArgumentsInferences(typeof(Func <IList <int>, string>), typeof(int[]), typeof(object)));
            AssertExt.AreEqual(new Type[] { typeof(IList <int>), typeof(object) },
                               method.GenericArgumentsInferences(typeof(Func <IList <int>, object>), typeof(int[]), typeof(string)));
            AssertExt.AreEqual(new Type[] { typeof(IList <int>), typeof(IList <int>) },
                               method.GenericArgumentsInferences(typeof(Func <IList <int>, int[]>), typeof(int[]), typeof(IList <int>)));
        }