コード例 #1
0
ファイル: Tests.cs プロジェクト: tonyhallett/ReflectObject
        public void Should_Work_With_Up_To_8_Func_Parameters()
        {
            var toReflect = new TestObject
            {
            };
            var testReflectObject = new TestReflectObject(toReflect);

            testReflectObject.Action();
            var funcReturn = testReflectObject.Func();

            Assert.AreEqual(0, funcReturn);
            List <Delegate> remainingActionDelegates = new List <Delegate>
            {
                testReflectObject.Func1,
                testReflectObject.Func2,
                testReflectObject.Func3,
                testReflectObject.Func4,
                testReflectObject.Func5,
                testReflectObject.Func6,
                testReflectObject.Func7,
                testReflectObject.Func8
            };
            var possibleArguments = new List <int> {
                1, 2, 3, 4, 5, 6, 7, 8
            };

            for (var i = 0; i < remainingActionDelegates.Count; i++)
            {
                var arguments = possibleArguments.Take(i + 1).Select(i => (object)i).ToArray();
                var result    = remainingActionDelegates[i].DynamicInvoke(arguments);
                Assert.AreEqual(arguments, toReflect.DelegateArguments);
                Assert.AreEqual(result, i + 1);
            }
        }
コード例 #2
0
ファイル: Tests.cs プロジェクト: tonyhallett/ReflectObject
        public void Should_Work_With_Up_To_8_Action_Parameters()
        {
            var toReflect = new TestObject
            {
            };
            var testReflectObject = new TestReflectObject(toReflect);

            testReflectObject.Action();
            Assert.IsEmpty(toReflect.DelegateArguments);
            List <Delegate> remainingActionDelegates = new List <Delegate>
            {
                testReflectObject.Action1,
                testReflectObject.Action2,
                testReflectObject.Action3,
                testReflectObject.Action4,
                testReflectObject.Action5,
                testReflectObject.Action6,
                testReflectObject.Action7,
                testReflectObject.Action8
            };
            var possibleArguments = new List <int> {
                1, 2, 3, 4, 5, 6, 7, 8
            };

            for (var i = 0; i < remainingActionDelegates.Count; i++)
            {
                var arguments = possibleArguments.Take(i + 1).Select(i => (object)i).ToArray();
                remainingActionDelegates[i].DynamicInvoke(arguments);
                Assert.AreEqual(arguments, toReflect.DelegateArguments);
            }
        }