Пример #1
0
        public void Test_assign_static_string_arg_string_return_delegate()
        {
            Type type = typeof(EventSource);

            type.AddHandler("StaticStringOp", args => (string)args[0] + "1");
            type.AddHandler("StaticStringOp", args => (string)args[0] + "2");
            string result = (string)type.InvokeDelegate("StaticStringOp", "A");

            Assert.AreEqual("A2", result);
        }
Пример #2
0
        public void Test_handle_static_int_arg_int_return_event()
        {
            Type type = typeof(EventSource);
            int  sum  = 0;

            type.AddHandler("StaticIntEvent", args => sum += (int)args[0] * 2);
            type.AddHandler("StaticIntEvent", args => sum += (int)args[0] * 3);
            object result = type.CallMethod("TriggerStaticEvents", 2);

            Assert.AreEqual(10, sum);
            Assert.AreEqual(10, result);
        }
Пример #3
0
        public void Test_handle_static_int_arg_int_return_delegate()
        {
            Type type = typeof(EventSource);
            int  sum  = 0;

            type.AddHandler("StaticIntOp", args => sum += (int)args[0] * 2);
            type.AddHandler("StaticIntOp", args => sum += (int)args[0] * 3);
            int result = (int)type.InvokeDelegate("StaticIntOp", 2);

            Assert.AreEqual(10, sum);
            Assert.AreEqual(10, result);
        }
Пример #4
0
        public void AddHandlerWorks()
        {
            bool invoked = false;
            var  c       = new TestType();

            Type.AddHandler(c, "Evt", (EventHandler)((s, e) => invoked = true));
            c.Raise();
            Assert.AreEqual(invoked, true);
        }
Пример #5
0
        public void Test(string arg)
        {
            Object o;
            bool   b;

            Type.InvokeMethod(o, arg);
            Type.InvokeMethod(o, "xyz");
            Type.InvokeMethod(o, "Proxy-Connection");
            Type.InvokeMethod(o, "xyz", 0);
            Type.InvokeMethod(o, "xyz", 0, arg);

            b = Type.HasMethod(o, arg);
            b = Type.HasMethod(o, "xyz");
            b = Type.HasMethod(typeof(Object), "xyz");

            Type.SetField(o, arg, 0);
            Type.SetField(o, "abc", 0);
            Type.SetField(o, "Proxy-Connection", 0);

            object v = Type.GetField(o, arg);

            v = Type.GetField(o, "abc");
            v = Type.GetField(o, "Proxy-Connection");

            b = Type.HasField(o, arg);
            b = Type.HasField(o, "abc");
            b = Type.HasField(typeof(Object), "abc");

            Type.SetProperty(o, arg, 0);
            Type.SetProperty(o, "def", 0);
            Type.SetProperty(o, "Proxy-Connection", 0);

            object v2 = Type.GetProperty(o, arg);

            v2 = Type.GetProperty(o, "def");
            v2 = Type.GetProperty(o, "Proxy-Connection");

            b = Type.HasProperty(o, arg);
            b = Type.HasProperty(o, "def");
            b = Type.HasProperty(typeof(Object), "def");

            Delegate handler;

            Type.AddHandler(o, arg, handler);
            Type.AddHandler(o, "mmm", handler);
            Type.AddHandler(o, "Proxy-Connection", handler);

            Type.RemoveHandler(o, arg, handler);
            Type.RemoveHandler(o, "mmm", handler);
            Type.RemoveHandler(o, "Proxy-Connection", handler);

            Type.DeleteField(o, "xyz");
            Type.DeleteField(o, "Proxy-Connection");
            Type.DeleteField(o, arg);

            Type t = Type.GetScriptType(o);

            if (Type.GetScriptType(o) == "object")
            {
            }

            if (Type.HasMethod(o, "execute"))
            {
            }

            Type.InvokeMethod(null, "globalMethod");
            Type.InvokeMethod(null, "globalMethod", "xyz");
        }