コード例 #1
0
        public void Execute(Runner my)
        {
            var prop = typeof(TestClass).GetProperty("TestProperty");
            var obj  = new TestClass();

            my.Execute("raw", i =>
            {
                obj.TestProperty = "asd";
            });

            var stdDel = (Action <TestClass, string>)Delegate.CreateDelegate(typeof(Action <TestClass, string>), prop.GetSetMethod());

            my.Execute("stddel", i =>
            {
                stdDel(obj, "asd");
            });

            var genDel = new MethodCache().GetSetter(prop);

            my.Execute("gendel", i =>
            {
                genDel(obj, "asd");
            });

            var cache  = new MethodCache();
            var method = prop.GetSetMethod();

            cache.GetInvoker(method);
            my.Execute("gendelc", i =>
            {
                cache.GetInvoker(method)(obj, "asd");
            });

            my.Execute("gendelc2", i =>
            {
                cache.GetSetter(prop)(obj, "asd");
            });

            my.Execute("invoke", i =>
            {
                method.Invoke(obj, new[] { "asd" });
            });

            my.Execute("setvalue", i =>
            {
                prop.SetValue(obj, "asd", null);
            });

            var settable = prop.ToSettable();

            my.Execute("settable", i =>
            {
                settable.Set(obj, "asd");
            });
        }
コード例 #2
0
        public void Execute(Runner my)
        {
            var prop = typeof(TestClass).GetProperty("TestProperty");
            var obj = new TestClass();

            my.Execute("raw", i =>
            {
                obj.TestProperty = "asd";
            });

            var stdDel = (Action<TestClass, string>)Delegate.CreateDelegate(typeof(Action<TestClass, string>), prop.GetSetMethod());
            my.Execute("stddel", i =>
            {
                stdDel(obj, "asd");
            });

            var genDel = new MethodCache().GetSetter(prop);
            my.Execute("gendel", i =>
            {
                genDel(obj, "asd");
            });

            var cache = new MethodCache();
            var method = prop.GetSetMethod();
            cache.GetInvoker(method);
            my.Execute("gendelc", i =>
            {
                cache.GetInvoker(method)(obj, "asd");
            });

            my.Execute("gendelc2", i =>
            {
                cache.GetSetter(prop)(obj, "asd");
            });

            my.Execute("invoke", i =>
            {
                method.Invoke(obj, new[] { "asd" });
            });

            my.Execute("setvalue", i =>
            {
                prop.SetValue(obj, "asd", null);
            });

            var settable = prop.ToSettable();
            my.Execute("settable", i =>
            {
                settable.Set(obj, "asd");
            });
        }
コード例 #3
0
        public void TestMethodCachedResult()
        {
            Type t = typeof(Sample1);
            MethodCache cache = new MethodCache();

            MethodInfo m1 = t.GetMethod("Method");
            InvocationDelegate d1 = cache.GetInvoker(m1);

            MethodInfo m2 = t.GetMethod("Method");
            InvocationDelegate d2 = cache.GetInvoker(m2);

            Assert.AreSame(m1, m2);
            Assert.AreSame(d1, d2);
        }
コード例 #4
0
        public void TestMethodCachedResult()
        {
            Type        t     = typeof(Sample1);
            MethodCache cache = new MethodCache();

            MethodInfo         m1 = t.GetMethod("Method");
            InvocationDelegate d1 = cache.GetInvoker(m1);

            MethodInfo         m2 = t.GetMethod("Method");
            InvocationDelegate d2 = cache.GetInvoker(m2);

            Assert.AreSame(m1, m2);
            Assert.AreSame(d1, d2);
        }