Beispiel #1
0
        public void TestCreateFromType()
        {
            var switcher = MethodSwitcher.Create <Func <object, string> >(typeof(TestClass));
            var valInt   = 10;

            Assert.AreEqual(TestClass.StaticMethod(valInt), switcher(valInt));
            var valLong = 10;

            Assert.AreEqual(TestClass.StaticMethod(valLong), switcher(valLong));
            var valStr = "10";

            Assert.AreEqual(TestClass.StaticMethod(valStr), switcher(valStr));
            var valIntArr = new int[2];

            Assert.AreEqual(TestClass.StaticMethod(valIntArr), switcher(valIntArr));
            var valLongArr = new long[2];

            Assert.AreEqual(TestClass.StaticMethod(valLongArr), switcher(valLongArr));
            var valStrArr = new string[3];

            Assert.AreEqual(TestClass.StaticMethod(valStrArr), switcher(valStrArr));
            var valObj = new object();

            Assert.AreEqual(TestClass.StaticMethod(valObj), switcher(valObj));
        }
Beispiel #2
0
        public void TestCreateFromObject()
        {
            var obj = new TestClass();

            obj.Value = "XXX";
            var switcher = MethodSwitcher.Create <Func <object, string> >(obj, "Ins");
            var valInt   = 10;

            Assert.AreEqual(obj.InstanceMethod(valInt), switcher(valInt));
            var valLong = 10;

            Assert.AreEqual(obj.InstanceMethod(valLong), switcher(valLong));
            var valStr = "10";

            Assert.AreEqual(obj.InstanceMethod(valStr), switcher(valStr));
            var valIntArr = new int[2];

            Assert.AreEqual(obj.InstanceMethod(valIntArr), switcher(valIntArr));
            var valLongArr = new long[2];

            Assert.AreEqual(obj.InstanceMethod(valLongArr), switcher(valLongArr));
            var valStrArr = new string[3];

            Assert.AreEqual(obj.InstanceMethod(valStrArr), switcher(valStrArr));
            var valObj = new object();

            Assert.AreEqual(obj.InstanceMethod(valObj), switcher(valObj));
        }
Beispiel #3
0
        public void TestCreateFromDelegates()
        {
            var switcher = MethodSwitcher.Create <Func <object, string> >(
                (Func <int, string>)TestClass.StaticMethod,
                (Func <string, string>)TestClass.StaticMethod,
                (Func <int[], string>)TestClass.StaticMethod,
                (Func <Array, string>)TestClass.StaticMethod,
                (Func <object, string>)TestClass.StaticMethod);
            var valInt = 10;

            Assert.AreEqual(TestClass.StaticMethod(valInt), switcher(valInt));
            var valLong = 10;

            Assert.AreEqual(TestClass.StaticMethod(valLong), switcher(valLong));
            var valStr = "10";

            Assert.AreEqual(TestClass.StaticMethod(valStr), switcher(valStr));
            var valIntArr = new int[2];

            Assert.AreEqual(TestClass.StaticMethod(valIntArr), switcher(valIntArr));
            var valLongArr = new long[2];

            Assert.AreEqual(TestClass.StaticMethod(valLongArr), switcher(valLongArr));
            var valStrArr = new string[3];

            Assert.AreEqual(TestClass.StaticMethod(valStrArr), switcher(valStrArr));
            var valObj = new object();

            Assert.AreEqual(TestClass.StaticMethod(valObj), switcher(valObj));
        }