public void InvokeFunctionWrapper()
        {
            FunctionWrapper <int, int, int, Func <int, int, int> > wrapper = new FunctionWrapper <int, int, int, Func <int, int, int> >(new Adder(), null);

            var result = wrapper.CreateFunctionDelegate().DynamicInvoke(2, 3);

            Assert.IsNotNull(result);
            Assert.AreEqual(5, result);
        }
示例#2
0
        public void CreateFunctionDelegate()
        {
            Context         environment = new Context();
            Runner          function    = new Runner();
            FunctionWrapper wrapper     = new FunctionWrapper(function, environment);
            var             @delegate   = wrapper.CreateFunctionDelegate();

            @delegate.DynamicInvoke();
            Assert.IsTrue(function.WasInvoked);
        }
        public void AddEventHandlerToPerson()
        {
            NameListener listener = new NameListener();
            Person       person   = new Person()
            {
                FirstName = "Adam"
            };
            FunctionWrapper <string, int, MyEvent> wrapper = new FunctionWrapper <string, int, MyEvent>(listener, null);

            typeof(Person).GetEvent("NameEvent").AddEventHandler(person, wrapper.CreateFunctionDelegate());
            person.GetName();

            Assert.AreEqual(4, listener.Length);
            Assert.AreEqual("Adam", listener.Name);
        }