public void TestPropertySetCachedResult()
        {
            Type        t     = typeof(Sample1);
            MethodCache cache = new MethodCache();

            PropertyInfo       p1 = t.GetProperty("Prop");
            InvocationDelegate d1 = cache.GetSetter(p1);

            PropertyInfo       p2 = t.GetProperty("Prop");
            InvocationDelegate d2 = cache.GetSetter(p2);

            Assert.AreSame(p1, p2);
            Assert.AreSame(d1, d2);
        }
Ejemplo n.º 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");
            });
        }
Ejemplo n.º 3
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");
            });
        }
Ejemplo n.º 4
0
        public void TestPropertySetCachedResult()
        {
            Type t = typeof(Sample1);
            MethodCache cache = new MethodCache();

            PropertyInfo p1 = t.GetProperty("Prop");
            InvocationDelegate d1 = cache.GetSetter(p1);

            PropertyInfo p2 = t.GetProperty("Prop");
            InvocationDelegate d2 = cache.GetSetter(p2);

            Assert.AreSame(p1, p2);
            Assert.AreSame(d1, d2);
        }